Link Search Menu Expand Document

Adjusting PDF compression options and optimization configurations

pdf/optimize function can compress input PDF into up to x13 smaller file size by compressing images and objects inside.

You can adjust compression options via profiles parameter that allows setting custom configurations.

profiles configuration is the JSON string {...}. For example:

{ 'ImageOptimizationFormat': 'JPEG', 'JPEGQuality': 25, 'ResampleImages': true, 'ResamplingResolution': 120, 'GrayscaleImages': false }

** profiles configuration variables**

  • ImageOptimizationFormat - (optional) controls image compression format. Available values:
    • JPEG (default) JPEG based compression;
    • Flate (zip-like compression);
    • Fax - 1-bit black and white compression, provides best file size;
  • JPEGQuality - (optional) controls JPEG compression quality from 1 (worst quality, smallest size) to 100 (best quality, largest size). Set to 25 by default.

  • ResampleImages - (optional) tells the compressor to resample images to a new resolution. true by default.

  • ResamplingResolution - (optional) target resampled images resolution. 120 by default (120 dots per inch).

  • GrayscaleImages - (optional) turns all images into grayscale. Not affecting the compression but useful if you need to make all images inside grayscale. False by default.

Compression Tests

4 page scanned PDF

4 page PDF with images, one image per page.

Input Sizeprofiles configurationOutput SizeOutput/Input %
566KBdefault (none)366KB64.66%
566KB{ 'JPEGQuality': 10}306KB54.06%
566KB{ 'ImageOptimizationFormat': 'Fax'}42KB7.42%

12-page presentation with text, drawings and images

12-page pdf presentation created and exported from Google Slides.

Input Sizeprofiles configurationOutput SizeOutput/Input %
3,169KBdefault (none)1,654KB52.19%
3,169KB{ 'JPEGQuality': 10}1,352KB42.66%
3,169KB{ 'ImageOptimizationFormat': 'Fax'}759KB23.95%
3,169KB{ 'ResamplingResolution': 72}1,552KB48.97%
3,169KB{ 'JPEGQuality': 10, 'GrayscaleImages': true}1,358KB42.85%

Example for settingprofiles in a direct API request

POST v1/pdf/optimize
{

"url": "https://bytescout-com.s3-us-west-2.amazonaws.com/files/demo-files/cloud-api/pdf-optimize/sample.pdf",
"profiles": "{ 'ImageOptimizationFormat': 'JPEG', 'JPEGQuality': 25, 'ResampleImages': true, 'ResamplingResolution': 120, 'GrayscaleImages': false }",
"async": false
}

200
{
"url": "https://pdf-temp-files.s3.us-west-2.amazonaws.com/Y99LLLYD3MD3HO7L159E8LN3OHWM92JA/sample-compressed.pdf?X-Amz-Expires=3600&X-Amz-Security-Token=FwoGZXIvYXdzEEsaDJ21qBMY7MLwxssbUyKCAYohRGJ8y2Gi2zauDThkWrpyxGcWPmBAdMxhmmHFKEhZ3ba%2F8XqL0PJ7vkcnoSzjZRcsFN8frq6rmvBo2seTWkZXnFgtLtfIWC8OjeLL1NnJW%2FwP9vT5jETb5H%2FC70hEqK0k0695lbTZkqZkdbRGvUK5%2FgnJzxmLEsP6Y3y5QYfefl0osOiLmQYyKAMrnezm5x7WEZvTiinr20Jl0aTM3ct4vCP60BK322V1mwqU5IIkGyU%3D&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=ASIA4NRRSZPHLKMV2RBQ/20220915/us-west-2/s3/aws4_request&X-Amz-Date=20220915T110758Z&X-Amz-SignedHeaders=host&X-Amz-Signature=c39c75e48626566e8aeb97bc5dca112428cfbd10691f39ab086f93d9992e8beb",
"pageCount": 5,
"error": false,
"status": 200,
"name": "sample-compressed.pdf",
"credits": 105,
"duration": 3023,
"remainingCredits": 5668833
}

Setting profiles in Zapier, Integromat/Make or other plugins

Find the PDF Compressor module and set profiles field as the following custom configuration:

{ 'ImageOptimizationFormat': 'JPEG', 'JPEGQuality': 25, 'ResampleImages': true, 'ResamplingResolution': 120, 'GrayscaleImages': false }

If PDF Compressor module is not available then consider using the Custom API Call module instead.

Setting profiles in Zapier, Integromat/Make or others in Custom API Call module

In the Custom API Call module set profiles parameter as in the following sample configuration:

{ 'ImageOptimizationFormat': 'JPEG', 'JPEGQuality': 25, 'ResampleImages': true, 'ResamplingResolution': 120, 'GrayscaleImages': false }