Send your files to our API and we'll do all the heavy lifting for you.
import fetch from "node-fetch";
import FormData from "form-data";
import fs from "fs";
const fileStream = fs.createReadStream("path/to/file.pdf");
const formData = new FormData();
formData.append("file", fileStream);
formData.append("quality", 2);
formData.append("grayscale", 1);
const token = "your_api_token";
fetch("https://webpdf.xyz/api/v1/pdf/compress", {
method: "POST",
headers: {
Accept: "application/json",
Authorization: `Bearer ${token}`,
...formData.getHeaders(),
},
body: formData,
});
$curl = curl_init();
$apiToken = 'your_api_token';
curl_setopt_array($curl, array(
CURLOPT_URL => "https://webpdf.xyz/api/v1/pdf/compress",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => array("file" => curl_file_create('path/to/file.pdf'), "quality" => 2, "grayscale" => true),
CURLOPT_HTTPHEADER => array('Accept:application/json', "Authorization: Bearer {$apiToken}"),
));
$response = curl_exec($curl);
use Illuminate\Support\Facades\Http;
$response = Http::acceptJson()
->withToken('your_api_token')
->attach(
'file', file_get_contents('path/to/file.pdf'), 'file.pdf')
->post(
'https://webpdf.xyz/api/v1/pdf/compress',
[
'quality' => 2,
'grayscale' => 0
]
)
->json();
import requests
response = requests.post(
'https://webpdf.xyz/api/v1/pdf/compress',
headers={'Accept': 'application/json', 'Authorization': 'Bearer your_api_token'},
files={'file': ('file.pdf', open('path/to/file.pdf', 'rb'), 'application/pdf')},
data={'quality': 2, 'grayscale': 0}
).json()
print(response)
import okhttp3.*;
import java.io.File;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "file.pdf",
RequestBody.create(MediaType.parse("application/pdf"), new File("path/to/file.pdf")))
.addFormDataPart("quality", "2")
.addFormDataPart("grayscale", "0")
.build();
Request request = new Request.Builder()
.url("https://webpdf.xyz/api/v1/pdf/compress")
.addHeader("Accept", "application/json")
.addHeader("Authorization", "Bearer your_api_token")
.post(requestBody)
.build();
}
}
require 'net/http'
require 'uri'
require 'json'
require 'mime/types'
require 'net/http/post/multipart'
url = URI.parse('https://webpdf.xyz/api/v1/pdf/compress')
file = File.open('path/to/file.pdf')
req = Net::HTTP::Post::Multipart.new url.path,
"file" => UploadIO.new(file, "application/pdf", "file.pdf"),
"quality" => '2',
"grayscale" => '0'
req['Accept'] = 'application/json'
req['Authorization'] = 'Bearer your_api_token'
res = Net::HTTP.start(url.host, url.port, use_ssl: url.scheme == 'https') do |http|
http.request(req)
end
file.close
package main
import (
"bytes"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
file, _ := os.Open("path/to/file.pdf")
defer file.Close()
var requestBody bytes.Buffer
writer := multipart.NewWriter(&requestBody)
part, _ := writer.CreateFormFile("file", "file.pdf")
io.Copy(part, file)
writer.WriteField("quality", "2")
writer.WriteField("grayscale", "0")
writer.Close()
req, _ := http.NewRequest("POST", "https://webpdf.xyz/api/v1/pdf/compress", &requestBody)
req.Header.Set("Content-Type", writer.FormDataContentType())
req.Header.Set("Accept", "application/json")
req.Header.Set("Authorization", "Bearer your_api_token")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
}
use reqwest::Client;
use std::path::Path;
#[tokio::main]
async fn main() {
let client = Client::new();
let form = reqwest::multipart::Form::new()
.file("file", "path/to/file.pdf")
.unwrap()
.text("quality", "2")
.text("grayscale", "0");
let res = client.post("https://webpdf.xyz/api/v1/pdf/compress")
.bearer_auth("your_api_token")
.multipart(form)
.send()
.await
.unwrap();
let body = res.text().await.unwrap();
println!("{}", body);
}
curl -X POST https://webpdf.xyz/api/v1/pdf/compress \
-H "Accept: application/json" \
-H "Authorization: Bearer your_api_token" \
-F "file=@path/to/file.pdf" \
-F "quality=2" \
-F "grayscale=0"
We squeeze all the juice from any PDF.
Here are the most important features.
PDF Compress
Merge or split PDF
Extract data from PDF
OCR PDF
Protect or Unlock PDF
Convert PDF to image
Tailored subscription plans to fit your ever-changing needs.
Use your montly credits for any operation you want.
$ 0 / month
$ 4 / month
$ 12 / month
Popular
$ 24 / month
WebPDF can help you scale with higher volume plans. Ask us about a dedicated plan.
You get charged only for successful requests.
Try them for FREE without an account.