16
December
2020
9:36

How to compress (reduce the file size) pdf

16 December 2020 9:36

Various public services portals accept files in electronic form of a strictly limited size. The usual requirement is a file size less than 5 MB. But many PDF files have a larger size due to the fact that the PDF format has recently been used for storing scanned documents. This message shows two ways to reduce the size of PDF files.

  1. In Linux, PDF compression is performed using the Ghostscript program.

First installed Ghostscript:

sudo apt-get install ghostscript

If you need more compression (possibly blurring text)

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/default -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

For the balance between the quality of the image and the size of the file (the small text is not blurred):

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output1.pdf input.pdf

Compression of the Input.pdf file with a resolution change in 300 by 300 dpi (with quality loss)

ghostscript -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -r300x300 -sOutputFile=output2.pdf input.pdf

When using Ghostscript, the file size is usually reduced - to 10 times. Sometimes well -compressed files come across - they will have to be processed in the second way, see below.

    1. In Windows, I usually convert PDF to a set of JPG raster images PDFill. Then, using a package operation in IRFANVIEW, I increase the degree of compression of JPEG with the export of the results into a separate catalogs. Finally, I transform the resulting set of pictures back to PDF.
  1. By analogy with PDFill in Windows, you can convert PDF from the Linux command line into a JPG series with a lower resolution (150 dpi instead of 300 dpi) and a higher compression coefficient (43 instead of 100).
    Then assemble the resulting pdf file from a JPEG file:

    convert -density 150 -quality 43 in.pdf out.jpg
    convert out-*.jpg out1.pdf

The file has become smaller. Examination:
ls -l in.pdf out1.pdf



Related publications