Sometimes you need to reduce the size of a PDF file in Linux so that you can email it to someone
This little script will do exactly that – in most circumstances. Be warned though it wont achieve good compression levels on all PDF files. It depends a lot on how the PDF file is constructed. For example I tried it on a file that contained screenshot images only and it made little to no difference to the PDF filesize. On the other hand, I tried it on a PDF that I generated from a scanner and it reduced the filesize a lot, easily enough to email. The command is:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=setting -sOutputFile=output.pdf input.pdf
Replace “input.pdf” with the name of your PDF file and “setting” with a desired quality level. You need to include the forward slash when entering the quality level.
Quality level settings are;
- /screen – the lowest resolution and lowest file size, but fine for viewing on a screen
- /ebook – a mid-point in resolution and file size
- /printer & /prepress – high-quality settings used for printing PDFs
Your mileage may vary with this, so test it out to see if it makes any difference.