Today almost every work is done with the help of a computer and the internet. Right from coaching students to delivering big projects at the organization level, everything can be done on a computer with the help of the internet.
Whether you’re filling an online form or delivering end-product documentation, everything needs to be done through file sharing. And this file is PDF file, because it is most secure file format out there. It keeps the data on file intact as you can not edit PDF files. Sometimes it becomes difficult to share or upload PDF file because of size limit restrictions on different websites.
Obviously, you cannot trim down the pages in the file to shrink the file size, then what you will do? Don’t worry, I’m here going to show you two ways to compress PDF file without compromising with data in it. There are two ways to achieve this, one is use GUI tool and other is to do it using command line. I’ll be using the later method. So, let’s get started.
Compress PDF Files Using Command Line Method
In command-line method, we’re going to use the tool named ghostscript, for compressing PDF files.
Before proceeding with compression method, make sure you have ghostscript installed on your Ubuntu desktop. If not, use the following command to install ghostscript.
$ sudo apt-get install ghostscript
Wait for the installation to complete. Now you can use following command to shrink the PDF file size.
$ gs -sDEVICE=pdfwrite -dComatibilityLevel=1.4 – dPDFSETTINGS=/prepress -dNOPAUSE -dQUIT -dBATCH -sOutputFile=compressed_PDF_filename.pdf inputfilename.pdf
Following are the -dPDFSETTINGS options, which you can use according to your need.
-dPDFSETTINGS=/screen: for lower quality and smaller size output.
-dPDFSETTINGS=/ebook: better quality with slightly larger file size.
-dPDFSETTINGS=/prepress: high quality output and size.
-dPDFSETTINGS=/printer: output ideal for printer quality.
Let’s, try to achieve this in the real world. For example, I will try to shrink this file named python_tutorial.pdf and give new file name python_tutorialcomp.pdf. Check below screenshot.
As you can see in the above screenshot, ghostscript successfully compressed the file size and created a new file named python_tutorialcomp.pdf.
So, this is how you can compress the PDF file size in Linux and its distributions like Ubuntu. Feel free to share your views with us in the comments below.