Compress PDF

Compress PDF API

File Tools

Make PDFs smaller in your browser by shrinking the images inside them. Text stays sharp and selectable, links and form fields keep working, and nothing is uploaded.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

20 requests per minute

Endpoints

1 endpoint available

Overview

Make a PDF smaller. The same engine as the web page:

  • light (150 DPI, quality 85), recommended (110 DPI, quality 72), strong (72 DPI, quality 55): images inside the PDF are scaled down to the target resolution and re-encoded as JPEG, only where that makes them smaller. Uncompressed streams are compressed and unused objects dropped. Text, links, bookmarks and form fields are kept.
  • maximum (100 DPI, quality 60): every page becomes a JPEG picture. Smallest for scans, but text is no longer selectable and links, bookmarks and form fields are lost.

dpi and quality override the level's settings.

Response

The body is a PDF. If compression did not make the file smaller, the original file is returned unchanged. These headers describe the result:

  • X-Original-Size: input size in bytes.
  • X-Output-Size: size of the returned file in bytes.
  • X-Compressed: true, or false when the original was returned.

Limits

  • One PDF up to 25 MB; 500 pages, or 100 pages for maximum.
  • Password-protected or damaged PDFs return 422.

Endpoints

POST
https://opentools.ca/api/v1/tools/compress-pdf
Compress a PDF by shrinking its images, or by turning pages into pictures

Request Body

Content-Type: multipart/form-data

ParameterTypeRequiredDescription
file
file
Required
The PDF to compress.
level
string
Enum: light, recommended, strong, maximum
OptionalCompression level.Default: recommended
dpi
integer
OptionalTarget image resolution, 36 to 300. Overrides the level.
quality
integer
OptionalJPEG quality, 20 to 95. Overrides the level.

Response Example

The compressed PDF (Content-Type: application/pdf, filename <name>-compressed.pdf), or the original file when it could not be made smaller. Headers: X-Original-Size, X-Output-Size, X-Compressed.

Error Codes

400
Bad Request - missing or invalid fields (see details)
401
Unauthorized - missing or invalid API key
403
Forbidden - API key inactive or expired, or request IP not allowed
413
Payload Too Large - a file is over 25 MB
415
Unsupported Media Type - the file is not a PDF
422
Unprocessable - the PDF is damaged or password-protected, or has too many pages for the level
429
Too Many Requests - more than 20 requests per minute for this key
500
Internal Server Error

Code Examples

curl -X POST https://opentools.ca/api/v1/tools/compress-pdf \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F "file=@brochure.pdf" \
  -F "level=strong" \
  -D headers.txt \
  -o brochure-compressed.pdf

Ready to get started?

Create an API key to start using the Compress PDF API.

Rather use it in your browser? Open the Compress PDF