Linux: Compress PDF – Reduce PDF Size

A scanned document saved as PDF can be too large, that is not always good.

For example, the large size of a PDF file won’t permit to send it by email because of the probable limitation on the maximum size of attachments.

In Linux you can compress a PDF file from the command line without losing its quality, with the help of ps2pdf tool, that is a part of ghostscript suite.

From this article you will learn how to compress a PDF file and significantly reduce its size from the Linux command line.

Cool Tip: Plan to send this PDF somewhere or just keep? How about to protect it with a password? This is really easy for ones who reduce the size of a PDF file from the command line! Read more →

First of all it is required to install the ghostscript suite that provides the ps2pdf utility:

$ sudo apt-get install ghostscript

Compress PDF File In Linux

Run the following command to compress and reduce the size of the LARGE.pdf file and save the result to the SMALL.pdf file:

$ ps2pdf LARGE.pdf SMALL.pdf

Effectiveness is obvious:

$ du -sh *.pdf
7,6M	LARGE.pdf
500K	SMALL.pdf

You can also add this command to reduces the size of a PDF file:

$ gs -sDEVICE=pdfwrite \
     -dCompatibilityLevel=1.4 \
     -dDownsampleColorImages=true \
     -dColorImageResolution=150 \
     -dNOPAUSE \
     -dBATCH \
     -sOutputFile=OUTPUT.pdf INPUT.pdf
Was it useful? Share this post with the world!

28 Replies to “Linux: Compress PDF – Reduce PDF Size”

  1. Thank you very much for your hack! It worked like a charm and I did learn something new.

  2. Exactly what I needed too. Thank you.

  3. Great “hack”. Compressed my PDF from 12,6 MB to 12,5 MB….

  4. wonderful: from 900.5 to 901.9. This is exactly what I was looking for! You made my day!

  5. from
    2.3M Fall_18-19-ACCT_422-PPT-11-1544528806-2018-12-11.pdf
    to
    2.6M Fall_18-19-ACCT_422-PPT-11-1544528806-2018-12-111.pdf
    hhhhhhhhhhhh

  6. Thank you for this! On average, my pdf files are being reduced to half their original size.

  7. Nonsense. This created a larger file.

  8. The real great hack! Have 1.5GB pdf after processing some pages, this stuff gives me a 6MB file. WOW! Want know, why.

  9. nothing happens, same file size

  10. For those who complain it doesn’t work make try another file. Perhaps the file you’re trying to compress is the smallest size possible and cannot be further compressed

  11. Peter Bennett says: Reply

    Converted a test file from 876k to 128k. I have hundreds of files and I can save a lot of space by running this on them. Thanks!

  12. It is impossible to reduce the size without affecting the quality, the total size of the PDF produced is lower than the size of one of the 30 images included in it.

  13. Camooon, its not fair!!! Wish i knew it before……… from 29M to 3.7m

  14. 20 MB -> 2 MB for me. Looks like this works for huge files. Not for those, that are already reasonably-sized.

  15. I used pdfunite to merge some pdfs and the result was a 295MB file, it went down to 16.5MB with ps2pdf. Thank you so much bro!

  16. Fantastic! Totally grateful for this : )

  17. I tried to use such technic, but it doesn`t work. I also attend to convert my file from pdf to djvu. It dicreased in size approximately two times, but work sighnificuntly quickly because djvu is better for scanned big-size file.

  18. $ gs -sDEVICE=pdfwrite \
         -dCompatibilityLevel=1.4 \
         -dDownsampleColorImages=true \
         -dColorImageResolution=150 \
         -dNOPAUSE \
         -dBATCH \
         -sOutputFile=output.pdf input.pdf
    1. Thanks, you save my day !!!

    2. Thanks, this comment is more helpful than the content of the webpage 😀

    3. Yes, this one works better for pdf with scanned images
      useful option for 150ppi all images
      -dPDFSETTINGS=/ebook

    4. A very elegant piece of code that did a wonderful job for me. Thank you!

  19. didn’t work for me. I made a 74.6MB pdf from hundreds of images and it remained same as before. maybe the images can’t be compressed any more.

  20. Wow, that;s effective

  21. Amazing article! This tool (ps2pdf) worked flawlessly for me! Thx!

  22. Thank you very much. From 7.6 MB to 757.3 kB

  23. From 67 MB to 9.9 MB. Thanks for this ShellHack!
    The guys that had a bigger file maybe lower resolution at `ColorImageResolution` parameter.
    I tested 75 DPI in place of 150 DPI, the file went to 4.2 MB but the images were bad.

  24. Amazingly effective, thank you.

Leave a Reply