Compress PDF API

Reduce PDF File Size While Maintaining Quality Programmatically.

hero banner

Code Examples in Popular Languages

Integrate our Compress PDF API easily into your apps with comprehensive code examples in popular languages to get started quickly.

CURL Request
curl --location 'https://theonlineconverter.com/api/v1/pdf-compressor' \
--header 'Content-Type: application/json' \
--header 'x-api-key: enter_your_api_key' \
--form 'file=@"/D:/data/Document/pdf/ebookebook.pdf"' \
--form 'compress_level="extreme"'
JavaScript Fetch
const myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("x-api-key", "enter_your_api_key");

const formdata = new FormData();
formdata.append("file", fileInput.files[0], "/D:/data/Document/pdf/ebookebook.pdf");
formdata.append("compress_level", "extreme");

const requestOptions = {
  method: "POST",
  headers: myHeaders,
  body: formdata,
  redirect: "follow"
};

fetch("https://theonlineconverter.com/api/v1/pdf-compressor", requestOptions)
  .then((response) => response.text())
  .then((result) => console.log(result))
  .catch((error) => console.error(error));
Ruby Net::HTTP
import requests
import json

url = "https://theonlineconverter.com/api/v1/pdf-compressor"

payload = {'compress_level': 'extreme'}
files=[
  ('file',('ebookebook.pdf',open('/D:/data/Document/pdf/ebookebook.pdf','rb'),'application/pdf'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
Python Requests
import requests
import json

url = "https://theonlineconverter.com/api/v1/pdf-compressor"

payload = {'compress_level': 'extreme'}
files=[
  ('file',('ebookebook.pdf',open('/D:/data/Document/pdf/ebookebook.pdf','rb'),'application/pdf'))
]
headers = {
  'Content-Type': 'application/json',
  'x-api-key': 'enter_your_api_key'
}

response = requests.request("POST", url, headers=headers, data=payload, files=files)

print(response.text)
PHP Guzzle
<?php
$client = new Client();
$headers = [
  'Content-Type' => 'application/json',
  'x-api-key' => 'enter_your_api_key'
];
$options = [
  'multipart' => [
    [
      'name' => 'file',
      'contents' => Utils::tryFopen('/D:/data/Document/pdf/ebookebook.pdf', 'r'),
      'filename' => '/D:/data/Document/pdf/ebookebook.pdf',
      'headers'  => [
        'Content-Type' => '<Content-type header>'
      ]
    ],
    [
      'name' => 'compress_level',
      'contents' => 'extreme'
    ]
]];
$request = new Request('POST', 'https://theonlineconverter.com/api/v1/pdf-compressor', $headers);
$res = $client->sendAsync($request, $options)->wait();
echo $res->getBody();
Java HttpURLConnection
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM)
  .addFormDataPart("file","/D:/data/Document/pdf/ebookebook.pdf",
    RequestBody.create(MediaType.parse("application/octet-stream"),
    new File("/D:/data/Document/pdf/ebookebook.pdf")))
  .addFormDataPart("compress_level","extreme")
  .build();
Request request = new Request.Builder()
  .url("https://theonlineconverter.com/api/v1/pdf-compressor")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("x-api-key", "enter_your_api_key")
  .build();
Response response = client.newCall(request).execute();
Go net/http
package main

import (
  "fmt"
  "bytes"
  "mime/multipart"
  "os"
  "path/filepath"
  "net/http"
  "io"
)

func main() {

  url := "https://theonlineconverter.com/api/v1/pdf-compressor"
  method := "POST"

  payload := &bytes.Buffer{}
  writer := multipart.NewWriter(payload)
  file, errFile1 := os.Open("/D:/data/Document/pdf/ebookebook.pdf")
  defer file.Close()
  part1,
         errFile1 := writer.CreateFormFile("file",filepath.Base("/D:/data/Document/pdf/ebookebook.pdf"))
  _, errFile1 = io.Copy(part1, file)
  if errFile1 != nil {
    fmt.Println(errFile1)
    return
  }
  _ = writer.WriteField("compress_level", "extreme")
  err := writer.Close()
  if err != nil {
    fmt.Println(err)
    return
  }


  client := &http.Client {
  }
  req, err := http.NewRequest(method, url, payload)

  if err != nil {
    fmt.Println(err)
    return
  }
  req.Header.Add("Content-Type", "application/json")
  req.Header.Add("x-api-key", "enter_your_api_key")

  req.Header.Set("Content-Type", writer.FormDataContentType())
  res, err := client.Do(req)
  if err != nil {
    fmt.Println(err)
    return
  }
  defer res.Body.Close()

  body, err := io.ReadAll(res.Body)
  if err != nil {
    fmt.Println(err)
    return
  }
  fmt.Println(string(body))
}
C# HttpClient
var options = new RestClientOptions("https://theonlineconverter.com")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("/api/v1/pdf-compressor", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("x-api-key", "enter_your_api_key");
request.AlwaysMultipartFormData = true;
request.AddFile("file", "/D:/data/Document/pdf/ebookebook.pdf");
request.AddParameter("compress_level", "extreme");
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

Key Features & Capabilities

Our API uses a suite of optimization techniques to intelligently reduce file size without compromising document integrity.

Simple User Interface

Intelligent Compression Engine

Our API analyzes the PDF content and applies multiple techniques, including image downsampling, font subsetting, and removing redundant data for optimal results.

Simple Data Format

Adjustable Compression Levels

Choose the perfect balance between file size and quality. Select from 'Recommended' for great quality, 'High' for stronger compression, or 'Extreme' for maximum size reduction.

Time

Quality Preservation

Our 'Recommended' setting is engineered to significantly reduce file size with minimal to no visible degradation in the quality of images and text.

Secure Data

Handles Scanned & Native PDFs

Effectively compresses both image-heavy scanned documents and text-based native PDFs, applying the best optimization methods for each type.

Universal Access

Batch Processing Ready

Automate the optimization of your entire document library by sending multiple compression jobs in sequence or parallel.

Freedom

Secure & Confidential

All files are processed over encrypted connections. We guarantee confidentiality with a strict data privacy policy and do not store your files.

Frequently Asked Questions

Find answers to common questions about our Compress PDF API to understand how it optimizes your documents.

It uses several methods. For images, it reduces resolution (downsampling) and applies efficient compression. It also removes embedded fonts that aren't used, merges duplicate objects, and flattens some elements to reduce the complexity of the file structure.

"Recommended" offers the best balance, significantly reducing size with very little visible quality loss. "High" applies more aggressive image compression, resulting in a smaller file but potentially some noticeable quality change. "Extreme" is for when file size is the absolute priority, and a significant drop in image quality is acceptable.

No. Vector-based text and line art are not affected in the same way as images. The text will remain sharp and searchable. Compression primarily targets the size of embedded images and the file's internal structure.

The reduction percentage varies greatly depending on the original file's content. A PDF with many large, unoptimized images will see a massive reduction (up to 90% or more), while a simple, text-only PDF will see a smaller reduction.

Yes, it is highly effective for scanned PDFs because they are essentially collections of images. Our API will significantly compress these images, leading to a much smaller file size.

Absolutely. The text layer of a searchable PDF is preserved during compression. Your document will remain fully searchable.

Yes. We use end-to-end TLS encryption for all data transfers. Your files are processed securely and are permanently deleted from our servers immediately after the compression is complete.