How to compress a PDF with an API
Updated 2026-10-12
Use when a PDF is too large to email or upload and its file size must be reduced. Add output=url for a 24 h link.
From an MCP client, add https://tanod.dev/mcp and call pdf_compress; calls are paid per use with x402, no key or signup.
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 -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:
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.pdfResponse
{
"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.
Free HTTP calls. /v1/pdf/compress has 2 free calls per IP per UTC day with X-Tanod-Free: 1, for inline base64 up to 1 MB (one pool with PDF to Word and document to Markdown). URL inputs and ordinary MCP calls are paid.
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.
Download link. Add "output": "url" to the request and the file is stored for 24 hours and returned as a link (url, expires_at, sha256) instead of base64, which keeps it out of your context window. The price is the same. How the links work.
Price and free allowance
USD 0.01 per call, paid in USDC on Base, Polygon, Solana, BNB Chain or Arbitrum with x402. The HTTP allowance above applies; ordinary MCP calls are paid. MCP tool: pdf_compress at https://tanod.dev/mcp.
Use it from Claude without writing code: in claude.ai or Claude Desktop, add https://tanod.dev/mcp/docs?via=compress-pdf-api as a custom connector (steps), then ask in plain words, for example "Make this PDF smaller so I can email it." Eligible Claude.ai connectors use a shared daily docs allowance; ordinary MCP calls are paid. Outside that allowance, a call needs an x402 payment, which these clients can make.
Related guides: PDF OCR API, 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, PDF APIs for agents: price per call. Back to tanod.dev or the guide index. Results are automated and heuristic.