Loading...

How to reduce PDF file size

One reason why PDF files can be large is due to the embeded high-resolution raster images, such as PNG or JPEG files. When a PDF contains images, particularly those with high resolution, it can significantly increase the overall file size.

There are 2 methods to reduce the file size of generated PDFs with large raster images:

Method 1: Pre-processed images Using Image Component (Recommended)

The image component, which includes an option to pre-process raster images.

Simply select an image component in the designer, then enable the option Pre-process Image in the property panel and specify the maximum width and height for the images.

Once enabled, the images will be processed before embedding them into the generated PDFs. This can notably reduce the resulting PDF file size, especially if it contains large raster images.

Method 2: Resample Raster Generated PDFs Using REST API

In our REST API, there's an option that allows you to adjust the resolution of raster images within the PDFs it generates.

By specifying the 'image_resample_res' option, you can optimize or down-sample the images to a desired DPI (dots per inch), which ultimately reduces the size of the PDF file. Common values for 'image_resample_res' include 1200, 600, 300, 150, or 72.

Please find out more about the option image_resample_res at

https://craftmypdf.com/docs/index.html#tag/PDF-Generation-API/operation/create

It's worth noting that compared to the method 1, method 2 of resampling the generated PDFs can consume more time and resources.

Conclusion

It's recommended to use the first method for preprocessing the images; it's more efficient and will also reduce the generation duration.