ubuntu小技巧

The fast way to Compress PDF in Linux(such as ubuntu)Terminal

The problem came when I tried to upload this PDF file. The upload failed because it exceeded the maximum file size limit. This only meant that I needed to somehow reduce the size of the PDF file.

Now, you may use an online PDF compressing website but I don’t trust them. A file with important documents uploading to an unknown server is not a good idea. You could never be sure that they don’t keep a copy your uploaded PDF document.

This is the reason why I prefer compressing PDF files on my system rather than uploading it to some random server. In this quick tutorial, I’ll show you how to reduce the size of PDF files in Linux. I’ll show both command line and GUI methods.

On Debian/Ubuntu based distributions, use the following command to install Ghostscript:

apt -y install ghostscript

Now that you have made sure that Ghostscript is installed, you can use the following command to reduce the size of your PDF file:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_PDF_file.pdf input_PDF_file.pdf

The command looks scary and confusing. I advise copying and pasting most of it. What you need to know is the dPDFSETTINGS parameter. This is what determines the compression level and thus the quality of your compressed PDF file.

dPDFSETTINGSDescription
/prepress (default)Higher quality output (300 dpi) but bigger size
/ebookMedium quality output (150 dpi) with moderate output file size
/screenLower quality output (72 dpi) but smallest possible output file size

Finally ,you can see pdf filesize from 11M to 2.5M, It’s very nice!

The fast way to Compress PDF in Linux(such as ubuntu)Terminal