Skip to main content

Compress PDFs with the API

Reduce the size of an existing PDF. Provide a publicly accessible HTTPS URL or a Base64-encoded file, choose a compression level, and receive the result as a PDF or temporary download link.

Try it in the Playground

Upload a PDF or add its URL, choose a compression level, and preview the result without writing code.

Try in Playground

Endpoints​

MethodEndpointSuccessful response
POST/v1/tools/compress/directPDF bytes with Content-Type: application/pdf
POST/v1/tools/compress/syncJSON with result metadata and a download URL when using default storage

Both endpoints wait for compression to complete before responding.

Authentication​

Use a conversion API key in the API-KEY header.

API-KEY: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX

Find your key on the API Credentials page in your Dashboard.

Compress a PDF from a URL​

The examples compress a sample PDF using medium compression and save the result as compressed.pdf. To use your own file, set url to its direct HTTPS URL.

The examples use the Direct endpoint. To receive a download URL, replace /direct with /sync and read the response as JSON. The documentUrl field contains the download URL.

{
"url": "https://pdfbolt.com/samples/pdf-compression-sample.pdf",
"compression": "medium"
}

Compress a Local PDF File​

Encode your PDF as Base64 and use the encoded data in the pdf field shown below, without the data:application/pdf;base64, prefix. The examples use medium compression and save the result as compressed.pdf.

{
"pdf": "BASE64_PDF",
"compression": "medium"
}

Request Parameters​

Set the Content-Type header to application/json. Include either url or pdf in the JSON body, not both.

url​

Type: string

Required: Yes, if pdf is omitted

Details: Direct, publicly accessible HTTPS URL of the input PDF. Maximum length: 2,048 characters.

URLs must not contain credentials or fragments such as #page=2. Redirects and private network addresses are not supported. Custom headers cannot be supplied when fetching the PDF.

pdf​

Type: string

Required: Yes, if url is omitted

Details: Base64-encoded contents of the input PDF, without the data:application/pdf;base64, prefix.

compression​

Type: string

Required: No

Default Value: lossless

Values: lossless, low, medium, high

Details: Selects the compression level. Higher levels reduce image quality to produce smaller files. See Compression Levels for details.

Usage:

{
"url": "https://pdfbolt.com/samples/pdf-compression-sample.pdf",
"compression": "low"
}

Send only url or pdf to use the default level.

filename​

Type: string

Required: No

Default Value: compress.pdf

Details: Output PDF filename in the Content-Disposition header. Maximum 255 characters. Allowed characters: A–Z, a–z, 0–9, ., _, and -. Provide the filename with or without the .pdf extension.

contentDisposition​

Type: string

Required: No

Default Value: inline

Details: Specifies whether the browser should display or download the PDF.

  • "inline": Display the PDF in the browser, if supported.
  • "attachment": Prompt a download.

Usage:

{
"pdf": "BASE64_PDF",
"compression": "medium",
"filename": "compressed.pdf",
"contentDisposition": "attachment"
}

customS3PresignedUrl​

Type: string

Required: No

Details: Uploads the compressed PDF to your S3-compatible bucket using an HTTPS pre-signed PUT URL. Available only with /v1/tools/compress/sync on paid plans. Maximum 2048 characters.

The URL must remain valid until the upload completes. On success, isCustomS3Bucket is true, and documentUrl and expiresAt are null. Omit this parameter to use PDFBolt's temporary storage.

See Uploading to Your S3 Bucket for setup details.

Usage:

{
"pdf": "BASE64_PDF",
"compression": "medium",
"filename": "compressed.pdf",
"contentDisposition": "attachment",
"customS3PresignedUrl": "https://your-bucket.s3.amazonaws.com/compressed.pdf?<presigned-query-params>"
}

Compression Levels​

LevelDescription
losslessDefault. Uses the highest image quality setting.
lowApplies light JPEG compression.
mediumApplies stronger JPEG compression, with a greater impact on image quality.
highUses the lowest JPEG quality setting. Compression artifacts may be more visible.

File size reduction depends on the document. Image-heavy PDFs generally benefit more than text-only or already optimized files. No level guarantees a specific reduction or output size.

If compression does not produce a smaller PDF, the API returns the original file as a successful response.

Successful Response​

The response format depends on the endpoint.

Returns HTTP 200 with the PDF in the response body.

Content-Type: application/pdf

Save the response body as a PDF file. The result is not stored for later download.

Failure Response​

Failed operations consume no credits. Check errorCode and errorMessage for details before retrying.

HTTP statusCommon causesAction
400Invalid parameters, an inaccessible URL or PDF download timeout, or an encrypted or invalid PDF.Check errorMessage and correct the input or settings.
400Custom S3 upload failed (CUSTOM_S3_UPLOAD_ERROR, Sync only).Check the pre-signed URL and upload permissions.
413The input PDF, request body, or output PDF exceeds its size limit.Reduce the file or request size.
See Limits and Credits.
422Processing exceeded its time limit (CONVERSION_TIMEOUT).Use smaller or less complex PDFs.

Example validation error:

{
"timestamp": "2026-11-04T10:00:00Z",
"httpErrorCode": 400,
"errorCode": "BAD_REQUEST",
"errorMessage": "Invalid Base64 PDF data."
}

See Error Handling for the shared error response format and other common errors.

Limits and Credits​

LimitValue
Input files per request1 PDF
Input PDF size100 MB

Compression is available on all plans. Encrypted, empty, and invalid PDFs are rejected. On the Free API plan, the output PDF is limited to 2 MB.

Successful requests cost one credit per started 5 MB of output. Credits are charged even when compression returns the original PDF.

Requests share your account's rate limits. The x-pdfbolt-conversion-cost response header reports the credits charged.