LogoDOCS
OverviewAuthenticationRate LimitsErrors
Logo
Sign in →

Compress PDF

The Compress PDF endpoint reduces the file size of a PDF without changing its visual appearance. You can also enable linearization so the first page loads faster when the PDF is opened over a network.

Note: In the sandbox environment, the compression result may be limited because our watermark image is automatically added to the document. As a result, the file size will be increased. We recommend testing this endpoint in the production environment.

Request Body
filefilerequired if documentId is not provided

File type: .pdf

The PDF file to be processed. Used when uploading a new file directly.

documentIdstringrequired if uploaded file is not provided

The ID of an already uploaded file stored on our server.

linearizeboolean

Default: false

When true, re-arranges the PDF for Fast Web View so the first page can render before the full file downloads.

jsonResponseboolean

Default: false

Returns JSON response instead of file stream.

preSignedUrlExpiresInnumber

Minimum: 60 seconds

Maximum: 86400 seconds (24 hours)

Use this to control temporary authorized access to files. After this duration, the URL automatically expires and can no longer be used to download the PDF. The value must be provided in seconds.

If you need to generate a new pre-signed URL for an existing document, use the Get Document endpoint.

metadataobject

Sets custom data to your document record.

POST/compress/pdf
CURL
NODE.JS
PYTHON
GO
PHP
JAVA
C#
RUBY
1curl -X POST "https://api.pdfgate.com/compress/pdf" \2  -H "Authorization: Bearer YOUR_API_KEY" \3  -F "file=@YOUR_FILE.pdf" \4  -F "linearize=true" \5  --output compressed.pdf
File stream response
1File stream
JSON response - Document object
1{2  "id" : "6642381c5c61",3  "status" : "completed",4  "fileUrl" : "https://api.pdfgate.com/file/open/:preSignedUrlToken",5  "size" : 1620006,6  "type" : "compressed",7  "derivedFrom" : "68f920bacfe16de217f019as",8  "createdAt" : "2024-02-13T15:56:12.607Z"9}