Compress and reduce PDF file size

You can compress PDFs using Document Engine.

Compressing PDFs

To compress a PDF, use the following example:

Terminal window
curl -X POST http://localhost:5000/api/build \
-H "Authorization: Token token=<API token>" \
-F document=@/path/to/example-document.pdf \
-F instructions='{
"parts": [
{
"file": "document"
}
],
"output": {
"type": "pdf",
"optimize": {
"grayscaleText": true,
"grayscaleGraphics": true,
"grayscaleFormFields": true,
"grayscaleAnnotations": true,
"disableImages": true,
"mrcCompression": true,
"imageOptimizationQuality": 2
}
}
}' \
-o result.pdf

Licensing

To compress PDFs with Document Engine, the Compression feature needs to be included in your license. Contact sales to add the feature to your license.

After the new component is added to your license, update the license or activation keys in your configuration.

Linearization

You can perform both linearization and compression in a single request to /api/build if both features are enabled in your license:

instructions = {
...
output: {
type: "pdf",
optimize: {
grayscaleText: true,
grayscaleGraphics: true,
grayscaleFormFields: true,
grayscaleAnnotations: true,
disableImages: true,
mrcCompression: true,
imageOptimizationQuality: 2,
linearize: true,
}
}
}

To learn more about linearization with Document Engine, refer to the linearization guide.