Linux shell script to reduce PDF file size

in Categories File-management, Script last updated November 27, 2019

Here is a handy and useful Linux and Unix shell script that reduce PDF file size using Ghostscript. No need to upload your PDF file to the shady third-party website. Just do it from the terminal. I tested it with both CentOS and Ubuntu/Debian Linux.

Unix and Linux shell script to reduce PDF file size

How to Reduce PDF File Size in Linux when using bash shell

Download and install the script in your system. Set up executable permissions using the chmod command:
chmod +x ~/bin/shrinkpdf.sh
Run it as follows:
~/bin/shrinkpdf.sh input.pdf output.pdf
~/bin/shrinkpdf.sh input.pdf output.pdf 100
~/bin/shrinkpdf.sh input.pdf output.pdf 120

Use the ls to list file size:
ls -lh input.pdf
ls -lh output.pdf

Unix and Linux shell script to reduce PDF file size

Comparing orignal vs compressed pdf file quality

  1. input.pdf (original file [1018K])
  2. output.pdf (compressed file [217K])

Conclusion

I often use this tiny script to reduce the file size of a scanned PDF file that I need to email/upload or store it on my NAS server for future reference. Most government or third party sites put restrictions on PDF file size uploads. Hence, using this script can help you reduce the size and upload files. The source of original shell script is here


Share this on:

Join the discussion at Linux/Unix forum

Historical Comment Archive

2 comment

    Have a question? Post it on our forum!