How to Reduce a PDF’s File Size with PDF.co
Compress a PDF when its file size exceeds an upload or attachment limit. Compression reduces the bytes used to store the document. It does not change its printed page dimensions, such as converting Letter pages to A4.
Results depend on the source file. High-resolution scans may offer more room for reduction than an already optimized text document. Compression can reduce image quality, so keep the original and review the compressed copy.
Step 1: Send a Compression Request
Use the PDF Compress API, POST /v2/pdf/compress.
Start with the medium preset. This is also the default when you omit compressionLevel.
Store your PDF.co API key in a local environment variable named PDFCO_API_KEY. Then run this example in a Bash-compatible terminal:
curl --fail-with-body --request POST \
'https://api.pdf.co/v2/pdf/compress' \
--header "x-api-key: $PDFCO_API_KEY" \
--header 'Content-Type: application/json' \
--data '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-compress/sample.pdf",
"compressionLevel": "medium",
"name": "compressed.pdf",
"async": false
}'Replace the sample URL when processing your own document. PDF.co must be able to retrieve the PDF directly.
For a protected source location, provide a temporary download URL or use the PDF.co file-upload API. A preview page requiring a browser login is not a direct download link.
Step 2: Choose the Compression Strength
Available presets are:
- low: Try when preserving image detail matters more than maximum reduction.
- medium: Start here and compare the result with the original.
- high: Try when medium remains too large and lower image resolution is acceptable.
- aggressive: Use the strongest preset only after reviewing its effect on image detail.
The optional colorQuality setting accepts values from 1 to 100. Higher values preserve more color and grayscale image quality and usually produce larger files.
Neither a preset nor a quality setting guarantees a particular final size.
Step 3: Download and Check the Result
The request returns JSON describing the result—not the PDF file itself.
Check the HTTP response and confirm that the JSON error field is false. Then download the PDF from the returned url before outputLinkValidTill.
Save the downloaded file in your own storage and compare:
- Original and compressed file sizes.
- The destination’s upload or attachment limit.
- Page count and document completeness.
- Small text, charts, photographs, and scanned details.
If the result remains too large, try a stronger preset using the original PDF and inspect the new output. Do not assume every PDF will become smaller.
Step 4: Use Background Processing for Longer Jobs
For long-running documents, set async to true.
Keep the returned jobId and use Background Job Check:
- working: Wait briefly, then check again.
- success: Retrieve and save the completed result.
- failed or aborted: Stop checking and inspect the response before retrying.
A job ID alone does not mean the compressed PDF is ready.
Questions About PDF File Size
What size should my PDF be?
Use the limit specified by the receiving service. There is no universal 1 MB or 5 MB requirement.
Is compression always lossless?
No. Image downsampling and JPEG compression can discard detail. Keep the original and review the output.
Will compression change the paper size?
No. File size and printed page dimensions are separate settings.
Can I send a Word document to this endpoint?
Supply a PDF. Convert other document formats to PDF first, then compress the resulting file if needed.
