Sometimes you may find problems when trying to upload a pdf file to a web site. It may be larger than the maximum allowed size. This is very annoying when you already reduced the contents of the file to a minimum or when you just can’t change its contents.
Fortunately, you can reduce the size of the pdf by just running a single line with the help of the program Ghostscript. First, let’s install it. Run the following code in the command line:
sudo apt-get install gs
Now, let’s reduce the file size of our pdf. For simplicity I used input.pdf and output.pdf for the filenames. You can change them to anything you want. In this case, obviously, input.pdf is the file that you have and output.pdf is the name of the generated pdf with a smaller size. If you just copy and paste the code remember to rename your pdf to input.pdf. Now run the following command.
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
Now look at output.pdf, or whichever name you used. It should be much smaller than the original. In my test case, I used an original pdf file with a file size of 3,023,501 bytes (around 3MB) and the output file had a file size of just 466,689 bytes (around 500 kB). That is six times smaller!. The compression is obtained by slightly reducing the quality of the images in the pdf and other optimizations.
You can also use this technique for saving storage space. Just run this command on your collection of pdf files to reduce their file size. That way you will preserve the contents of the pdf but you will be using much smaller file sizes. Also, when sending pdfs for revisions, you can save time by sending smaller files!.