PDF Optimize#
This function can compress input PDF files up to 13 times smaller in file size by compressing images and objects inside.
You can adjust compression options via the profiles
parameter that allows setting custom configurations.
Available Methods#
/pdf/optimize#
Optimize a PDF document to reduce its size.
Method: POST
Endpoint: /v1/pdf/optimize
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/file1.pdf"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
HTTP auth user name if required to access source |
no |
|
HTTP auth password if required to access source |
no |
|
File name for the generated output, the input must be in string format. |
no |
|
Set the expiration time for the output link in minutes (default is |
no |
|
Password of PDF file, the input must be in string format. |
no |
|
Set |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Query parameters#
No query parameters accepted.
Payload#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-optimize/sample.pdf",
"name": "output.pdf",
"profiles": "{ 'ImageOptimizationFormat': 'JPEG', 'JPEGQuality': 25, 'ResampleImages': true, 'ResamplingResolution': 120, 'GrayscaleImages': false }",
"async": false
}
Response 2#
{
"url": "https://pdf-temp-files.s3.us-west-2.amazonaws.com/TEPHYOOWTKN47RSMF11CXHXHD7U68ZSS/sample-compressed.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEEsaDMAT9Cnzd6%2FnDfVKYSKCAU6XCvsgWTRfJHWmoO2iJfJ6YSVShb6ddOXU9Ks5G4Ai20O2idqOaLLslwt6uEnT9EbwpzBMEXuqREkoTTmUOEcXJi9zO5lkLoQ16tXCbfmUF8cvJxVYBXGRHJlzHQ20kJtN6lP237e8rlMtNRIK0f1QsIQswfWy2BFz8IuOndZRu8goquiLmQYyKBBjAmoWcEqs0iMA7MizFAdIbFGydTYXcptaixm%2F%2BfayUZKUByJHURU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHNTO33MZG/20220915/us-west-2/s3/aws4_request&X-Amz-Date=20220915T135207Z&X-Amz-SignedHeaders=host&X-Amz-Signature=4f3334f68f1a98d3a9bfe09ec03d3e7d10fb7709ce58b711e36652c59a4d6b4a",
"fileSize": 798621,
"pageCount": 5,
"error": false,
"status": 200,
"name": "sample-compressed.pdf",
"credits": 105,
"duration": 2886,
"remainingCredits": 98256037
}
CURL#
curl --location --request POST 'https://api.pdf.co/v1/pdf/optimize' \
--header 'Content-Type: application/json' \
--header 'x-api-key: ' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-optimize/sample.pdf",
"name": "output.pdf",
"profiles": "{ '\''ImageOptimizationFormat'\'': '\''JPEG'\'', '\''JPEGQuality'\'': 25, '\''ResampleImages'\'': true, '\''ResamplingResolution'\'': 120, '\''GrayscaleImages'\'': false }",
"async": false
}'
Footnotes
- 1
Supports links from Google Drive, Dropbox, and PDF.co Built-In Files Storage. To upload files via the API check out the File Upload section. Note: If you experience intermittent Access Denied or Too Many Requests errors, please try to add
cache:
to enable built-in URL caching. (e.gcache:https://example.com/file1.pdf
) For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.- 2
Main response codes as follows:
Code
Description
200
Success
400
Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.
401
Unauthorized
402
Not enough credits
445
Timeout error. To process large documents or files please use asynchronous mode (set the
async
parameter totrue
) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using thepages
parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.Note
For more see the complete list of available response codes.