How to easily compress a PDF file in Linux without risking exposing your sensitive data online

Using Ghostscript to compress a PDF on your local machine on Linux

First, find a way to install the Ghostscript binary on their Installation docs page. In my case, Ghostscript came pre-installed on Manjaro, so I didn't have to do anything to get it :)

Then run this command from the terminal:

gs -sDEVICE=pdfwrite \
-dCompatibilityLevel=1.4 \
-dPDFSETTINGS=<my-compression-preset> \
-dNOPAUSE \
-dQUIET \
-dBATCH \
-sOutputFile=my-compressed-file.pdf \
my-uncompressed-file.pdf

where <my-compression-preset> must be replaced by one of the following values as per their documentation:

I recommend to try out the different presets to find out if the quality degradation vs size-reduction is working for you.

For me, the first time I used this I went with the /prepress preset and it was good enough to bypass the file uploader form constraint I was trying to circumvent.

Resources

Taken from: It's FOSS

Reference: Ghostscript docs