Documentation Index
Fetch the complete documentation index at: https://docs.pdf.co/llms.txt
Use this file to discover all available pages before exploring further.
POST /v2/pdf/compress
Allows for more granular control over PDF compression with enhanced results.
Attributes
Attributes are case-sensitive and should be inside JSON for POST request. for example:
{ "url": "https://example.com/file1.pdf" }| Attribute | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | URL to the source file url attribute |
config | object | No | - | Configuration options. By default this object is pre-defined to give typical options for optimization. |
httpusername | string | No | - | HTTP auth user name if required to access source URL. |
httppassword | string | No | - | HTTP auth password if required to access source URL. |
pages | string | No | all pages | Specify page indices as comma-separated values or ranges to process (e.g. “0, 1, 2-” or “1, 2, 3-7”). The first-page index is 0. Use ”!” before a number for inverted page numbers (e.g. “!0” for the last page). If not specified, the default configuration processes all pages. The input must be in string format. |
password | string | No | - | Password for the PDF file. |
async | boolean | No | false | Set async to true for long processes to run in the background, API will then return a jobId which you can use with the Background Job Check endpoint. Also see Webhooks & Callbacks |
name | string | No | - | File name for the generated output, the input must be in string format. |
expiration | integer | No | 60 | Set the expiration time for the output link in minutes. After this specified duration, any generated output file(s) will be automatically deleted from PDF.co Temporary Files Storage. The maximum duration for link expiration varies based on your current subscription plan. To store permanent input files (e.g. re-usable images, pdf templates, documents) consider using PDF.co Built-In Files Storage. |
profiles | object | No | - | See Profiles for more information. |
outputDataFormat | string | No | - | If you require your output as base64 format, set this to base64 |
JPEGQuality | integer | No | 25 | Controls JPEG compression quality from 1 (worst quality, smallest size) to 100 (best quality, largest size). |
config
The config object defines granular settings for the compression process as follows:
| Attribute | Description | Required |
|---|---|---|
images | Contains key/value pairs to define how images should be compressed. | Yes |
save | Contains key/value pairs to define how saving should be performed. | Yes |
config.images
Image compression options. Each key defines how to treat certain image types in the document. In this way you can target color, grayscale or monochrome images with different approaches.
Each key above takes the same bundle of key/value pairs as follows:
Downsample & Compression object
config.images.color, config.images.grayscale & config.images.monochrome all utlize this object schema.
Downsample object
Here you can choose the target ppi / threshold ppi or skip downsampling if you want. The threshold ppi is the limit for which to start downsizing from and the downsample ppi is the target ppi to meet.Example: If the threshold ppi (
threshold_ppi) is 400 and downsample ppi (downsample_ppi) is 250, it will reduce the resolution to 250 ppi for any images with resolution equal or higher than 400 ppi.| Key | Type | Description |
|---|---|---|
skip | boolean. Default isfalse. | Boolean to indicate whether to skip downsizing. |
downsample_ppi | number | The target PPI. Default is150forcolorandgrayscale,300formonochrome. |
threshold_ppi | number | The threshold PPI. Default is225forcolorandgrayscale,450formonochrome. |
Compression object
Here you can choose different compression options for each image type:color, grayscale or monochrome.
| Key | Type | Description |
|---|---|---|
skip | boolean. Default isfalse. | Boolean to indicate whether to skip compressing. |
compression_format | string | Available algorithms arejpeg,jpeg2000,CCITTGroup4,CCITTGroup3,zip. |
compression_params | object | An object which contains the quality settings. |
Compression parameters object
Depending on what you have set for thecompression_format algorithm you have different options.
jpeg: can choose qualityjpeg2000: can choose quality and layers
| Key | Type | Description |
|---|---|---|
quality | number | The quality setting for the image,0~100. Default is60. |
--- | --- | --- |
| quality_mode | string. Either “rates” or “dB” depending on the units you want to use to specify image quality. Default is “rates”. | String used to define quality mode for JPEG2000. |
| quality_layers | number[]. A sequence of numbers, each of which represents either an approximate size reduction (if quality mode is “rates”) or a signal to noise ratio value in decibels. If not specified, defaults to a single layer of full quality. Default is[30]ifquality_modeis “rates”. Default is[38.0,34.0,30.0]ifquality_modeis “dB”. | An array of numbers for the layers. |
Example
config.save
Contains one key for use with garbage collection to free up space that has been allocated to objects no longer needed.
| Key | Type | Description |
|---|---|---|
garbage | number | Garbage collection option. |
config.save.garbage
| Value | Description |
|---|---|
0 | none |
1 | remove unused (unreferenced) objects. |
2 | in addition to 1, compact the xref table. |
3 | in addition to 2, merge duplicate objects. |
4(default) | in addition to 3, check stream objects for duplication. |
The default config object
The defaultconfig is set to match the standard configuration for image optimization by Adobe Acrobat Pro and is defined as follows:
Query parameters
No query parameters accepted.Responses
| Parameter | Type | Description |
|---|---|---|
pageCount | integer | Number of pages in the PDF document. |
error | boolean | Indicates whether an error occurred (false means success) |
status | string | Status code of the request (200, 404, 500, etc.). For more information, see Response Codes. |
credits | integer | Number of credits consumed by the request |
remainingCredits | integer | Number of credits remaining in the account |
duration | integer | Time taken for the operation in milliseconds |
url | string | Direct URL to the final PDF file stored in S3. |
name | string | Name of the output file |
outputLinkValidTill | string | Timestamp indicating when the output link will expire |
Example Payload
To see the request size limits, please refer to the Request Size Limits.
Example Response
To see the main response codes, please refer to the Response Codes page.
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.Code Samples
- CURL (Simple use case)
- CURL (Defining configuration options)
- JavaScript/Node.js
- Python
- C#
- Java
- PHP