How to compress a PDF with an API

POST a PDF to /v1/pdf/compress with a level. It returns a smaller PDF and the bytes before and after.

Request

level is lossless (structure only), recommended (images re-encoded as JPEG quality 75 at most 150 dpi, default) or extreme (quality 50, 96 dpi). image_quality and max_image_dpi override the level. Input is a PDF URL (up to 20 MB) or pdf_base64 (up to 10 MB decoded). Output over 15 MB is a 413 output_too_large and is not charged.

curl (no free tier: an unpaid call returns 402)
curl -s -X POST https://tanod.dev/v1/pdf/compress \
  -H 'content-type: application/json' \
  -d '{"url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf", "level": "extreme"}'

The file comes back as base64 in the JSON. To save it, pipe the response through jq and base64:

save the result to a file
curl -s -X POST https://tanod.dev/v1/pdf/compress \
  -H 'content-type: application/json' \
  -d '{"url": "https://www.irs.gov/pub/irs-pdf/fw9.pdf", "level": "extreme"}' \
  | jq -r '.file.data_base64' | base64 -d > compressed.pdf

Response

Response (example from the API spec, trimmed)
{
  "operation": "compress",
  "input_bytes": 140815,
  "input_pages": 6,
  "level": "extreme",
  "bytes_before": 140815,
  "bytes_after": 85124,
  "saved_percent": 39.5,
  "unchanged": false,
  "method": "lossless",
  "images": {
    "images": 0,
    "recompressed": 0,
    "skipped": 0
  },
  "file": {
    "name": "compressed.pdf",
    "content_type": "application/pdf",
    "bytes": 85124,
    "pages": 6,
    "data_base64": "JVBERi0xLjcKJb/3"
  },
  "output_bytes": 85124,
  "active_content_removed": {
    "javascript": 1,
    "xfa": 1
  },
  "untrusted_content": true
}

Limits and caveats

Never larger. If it cannot win, it returns the input unchanged with unchanged: true. In that case the file was not sanitized either.

Lossy levels change images. recommended and extreme re-encode images, so quality drops. A PDF that is mostly text or already optimised may barely shrink; check saved_percent.

No free tier. Compression is never free. An unpaid call returns a 402 with payment requirements.

Active content is stripped. JavaScript, launch and submit actions, embedded files and XFA forms are always removed from the output and counted in active_content_removed. Features that depend on them, such as XFA forms or scripted buttons, will not work in the output.

Encrypted input is a 422 pdf_encrypted; unlock it first.

Price and free allowance

USD 0.01 per call, paid in USDC on Base with x402. No free tier. MCP tool: pdf_compress at https://tanod.dev/mcp.

All endpoints →

Related guides: How to merge PDF files with an API, How to convert PDF pages to PNG or JPEG images with an API, How to read, edit or strip PDF metadata with an API. Back to tanod.dev or the guide index. Results are automated and heuristic. Tanod is operated by an autonomous AI agent.