How to Compress PDF in Linux [GUI & Terminal]

Learn how to reduce the size of a PDF file in Linux. Both command line and GUI methods have been discussed.
Warp Terminal

I was filling some application form and it asked to upload the necessary documents in PDF format. Not a big issue. I gathered all the scanned images and combined them in one PDF using gscan2pdf tool.

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.

Method 1: Reduce PDF file size in Linux command line

Compress Pdf Linux

You can use Ghostscript command line tool for compressing a PDF file. Most Linux distributions include the open source version of Ghostscript already. However, you can still try to install it just to make sure.

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

sudo apt 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

In the above command, you should add the correct path of the input and out PDF file.

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.

/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

Do keep in mind that some PDF files may not be compressed a lot or at all. Applying compression on some PDF files may even produce a file bigger than the original. There is not much you can do in such cases.

Method 2: Compress PDF files in Linux using GUI tool

I understand that not everyone is comfortable with command line tool. The PDF editors in Linux doesn’t help much with compression. This is why we at It’s FOSS worked on creating a GUI version of the Ghostscript command that you saw above.

Panos from It’s FOSS team worked on creating a Python-Qt based GUI wrapper for the Ghostscript. The tool gives you a simple UI where you can select your input file, select a compression level and click on the compress button to compress the PDF file.

Compress Pdf

The compressed PDF file is saved in the same folder as the original PDF file. Your original PDF file remains untouched. The compressed file is renamed by appending -compressed to the original file name.

If you are not satisfied with the compression, you can choose another compression level and compress the file again.

You may find the source code of the PDF Compressor on our GitHub repository. To let you easily use the tool, we have packaged it in AppImage format. Please refer to this guide to know how to use AppImage.

Please keep in mind that the tool is in early stages of developments. You may experience some issues. If you do, please let us know in the comments or even better, file a bug here.

We’ll try to add more packages (Snap, Deb, PPAs etc) in the future releases. If you have experience with the development and packaging, please feel free to give us a hand.

Would you like It’s FOSS team to work on creating more such small desktop tools in future? Your feedback and suggestions are welcome.

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries 🕵️‍♂️

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world


Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.