Skip to main content
Try it live: PDF Compress → API Tester — send a real request from your browser.

POST /v2/pdf/compress

This is the current PDF compression endpoint. The legacy PDF Optimize V1 endpoint is deprecated.

Quick start

A request containing only url automatically uses the medium preset, so you can start compressing immediately.
Start with the medium preset for balanced compression. Choose another preset only when you need lighter or stronger compression.
To see the request size limits, please refer to the Request Size Limits.

Choose a preset

For most files, choose one of four compression_level values. You do not need to understand the advanced configuration to use them.
  • low — Light compression with the highest image resolution.
  • medium — Balanced compression based on Adobe Standard resolution targets.
  • high — Stronger compression with lower image resolution.
  • aggressive — The smallest images and strongest compression of the four presets.
You can also set color_quality from 1 to 100. Higher values preserve more color and grayscale image quality and usually produce larger files. The default is 60.
Preset request body
Exact PPI thresholds used by each preset.

Request body

Attributes are case-sensitive and should be inside JSON for POST request. for example: { "url": "https://example.com/file1.pdf" } There are no query parameters.
string
required
URL of the source PDF. The endpoint processes the complete document. The URL must be reachable by PDF.co — see supported file sources. For a protected source location, provide a temporary or presigned URL.
string
Ready-to-use compression profile: low, medium, high, or aggressive. When omitted, medium is applied. Presets also enable font subsetting and font stream compression.
integer
default:"60"
JPEG quality for color and grayscale images, from 1 for the smallest file and lowest quality to 100 for the highest quality. It can be used with or without compression_level.
string
Password for opening an encrypted source PDF. Omit it for an unprotected PDF.
boolean
default:"false"
Set to true for large or long-running documents. The initial response includes jobId; use the Background Job Check endpoint to retrieve the final status. Also see Webhooks & Callbacks.
string
Callback URL notified when an asynchronous job finishes. Use it with async: true.
string
Output file name. The endpoint appends .pdf when needed. If omitted, it derives the name from url when possible.
integer
default:"60"
Number of minutes before the temporary output URL expires. After this period, generated files are deleted from PDF.co Temporary Files Storage. The maximum retention depends on your subscription plan. To store permanent input files (e.g. re-usable images, pdf templates, documents) consider using PDF.co Built-In Files Storage.
The current V2 Compress implementation does not use httpusername or httppassword. The old profiles.outputDataFormat and profiles.JPEGQuality descriptions also do not apply to this endpoint.

Advanced configuration

Use config only when a preset is not enough. It is a partial object: you only send the values you want to override.
  1. PDF.co starts with the standard configuration.
  2. It applies medium, or the selected compression_level.
  3. It applies color_quality, when supplied.
  4. It deep-merges config as the final override.
Specify the narrowest override you need. Every omitted value continues to come from the base configuration, or from the preset and color_quality you selected.
Each preset resolves to an effective configuration for the first compression pass. All presets use JPEG quality 60 for color and grayscale images, CCITT Group 4 for monochrome images, font subsetting and compression, and garbage collection level 4. Their resolution targets differ per the Preset resolution targets table above.To represent another preset, change the four PPI values using that table. To represent a different color_quality, change both JPEG quality values.The effective values produced by the medium preset:
Use compression_level when a preset already fits your needs. The configuration above produces the same first pass, but explicit config values are preserved during the standard fallback retry, so manually copying a complete preset can change fallback behavior.

Common config recipes

These examples show only the request fields relevant to the change. Add the same fields to the request body together with url.
Keep the base encoding and fonts, but retain more color and grayscale detail. Images are reduced to 200 PPI only when their effective resolution is above 300 PPI. Monochrome images keep the base settings.
Preserve pixel dimensions while still applying the selected image encoding. The default preset encoding is JPEG.
Do not downsample or re-encode monochrome images.
Start with high, preserve more image quality, and make two exceptions. This keeps the high resolution targets, uses color quality 90, leaves monochrome images unchanged, and disables font subsetting. Font stream compression remains enabled.

What each skip setting does

object
Advanced image, font, and save controls.
Fallback base used when the first compression pass is not smaller. A request containing only url uses medium for its first pass; this fallback has the same image settings but does not subset or compress fonts.

Behavior notes

  • Compression results depend on the source PDF. Presets do not promise a fixed reduction, and two levels can produce the same file size.
  • When the first compression pass does not produce a smaller PDF, PDF.co retries with the standard configuration while preserving explicit config overrides. If the retry is also not smaller, it returns the original PDF.
  • Each re-encoded image is kept only when its new stream is smaller. If effective PPI cannot be determined, downsampling is skipped but re-encoding can still run at the original dimensions.

Responses

A synchronous success returns the final temporary output URL.
Synchronous response
An asynchronous request returns a jobId and a reserved URL that should be used only after the job succeeds. Poll it via Background Job Check. Errors return error: true with a status code and message. See the response examples and Response Codes.
Inconsistent URL Encoding in cURL Output: When using cURL to make API requests, the output JSON may show URL characters encoded as Unicode escape sequences. For example, the ampersand character (&) may appear as \u0026 in the cURL output. This is normal JSON encoding behavior and does not affect the validity of the URL. The URL will function correctly when used, as JSON parsers automatically decode these escape sequences. If you’re parsing the response programmatically, your JSON parser will handle this conversion automatically.