How to Compress PDF in Ubuntu

If you are using Ubuntu, chances, if you are using Libre Office or Open Office, are pretty much high. You can easily make PDF files from them but you don’t get any tool in Ubuntu to compress PDFs.

In many cases, PDF files get large enough to exceed size limits in uploads such as you have a limit to upload PDF files in Google Forms of 25 MB. We will discuss several solutions for reducing PDF size in Ubuntu.

Compressing PDF in Ubuntu

There are many ways by which you can compress PDF in your Ubuntu system but we have selected 3 ways that will work flawlessly for your PDF compression.

  • Using an online PDF compression tool
  • Using Command-line tool
  • Using GUI

All of these methods would work fine on Debian-based distros such as Linux Mint, MX Linux, Pop_Os, and many others

Compressing PDF using Online Compression Tool

This is the easiest method of all. Several online sites give you the privilege to compress your PDF files for free but Smallpdf has always worked fine. The main facility that it gives you is previewing PDF files before downloading.

Step 1: Open Smallpdf

You can use any of your favorite browsers for visiting the Compress PDF section of Smallpdf. Click on CHOOSE FILES.

1. click on upload files

Step 2: Selecting Files for Compression

When you will click on CHOOSE FILES, it will open your File manager. From there select the required PDF file that you want to compress. And click on Open.

2. uploading files

As we are going with the free plan, select Basic Compression and click on Compress.

3. selecting basic plan

Step 3: Previewing and downloading

Once the file is compressed, you will be able to see the size. In our case, the upload size was 4.89 MB and it is been compressed to 679 KB.

Click on Download and your compressed PDF will be downloaded.

4. downloading PDF

You do have other options such as Splitting PDF, Protecting PDF, and others. You can easily continue with those options with a compressed file without downloading it.

Compressing PDF using Terminal

A terminal is a great tool especially when you want to complete tasks with efficiency. Similarly, we have a tool called Ghostscript. Unlike 1st option, you can compress your file as per your preference for free.

Step 1: Updating Repositories

Before downloading anything, it is always advised to update your repositories so that you can have the latest and most stable version available for your system. Use the given command for updating your system.

 sudo apt update && sudo apt upgrade -y 

1. sudo apt update _ sudo apt upgrade -y

Step 2: Downloading Ghostscript

Once your system is updated with the above command, you can use the following command to install Ghostscript.

 sudo apt install ghostscript 

2. sudo apt install Ghostscript

Step 3: Compressing PDF files using Ghostscript

Now we are ready for compressing PDF files using Ghostscript but before that let’s have a look at its syntax and what does each command mean.

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf 

Don’t get nervous about this complex command. There are only 3 things in the whole string of commands which should concern you.

Changing quality by -dPDFSETTINGS

Renaming the output file by -sOutputFile

Inserting PDF file which you want to compress at the end of the command (we will replace the name of the PDF file with input.pdf)

You will have to get into the folder where your PDF file is located. In my system, it’s located at /Documents/PDF. I will use the given command to change my current directory to the desired one.

 cd Documents/PDF/ 

3. cd

Compressing files in High Quality using /prepress

This will give you the highest quality which Ghostscript has to offer with the least compression. Open your Terminal and use the following command

After Entering our desired directory, we are required to identify the exact file which we are going to compress. Use the given command to list down all files in the current folder

 ls 

3. ls

After identifying your file from the list, use this command to compress it.

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed-file.pdf e-Notes_PDF_All-Units_27042019042410AM.pdf 

4. prepress

As you can see, we have changed the input file, renamed the output file compressed-file.pdf

To check the results, use the following command to list down the number of files

 ls 

5. ls for final

This time, it has shown us a second file named compressed-file.pdf

Compressing files in Balanced-Quality using /ebook

If you want to have a medium quality and medium compression, use can use this method. It will compress PDF in 150 dpi which is balanced in terms of quality and size.

To list down available files in a folder using the following command:

 ls 

ls 2

Use given command for compression:

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed-file1.pdf e-Notes_PDF_All-Units_27042019042410AM.pdf 

6. ebbok

As you can see, we have changed the type of compression to ebook and its output is renamed compressed-file2.pdf

Compressing files at a Higher compression rate using /a screen

This will give you the highest level of compression with low-quality PDF (with 72dpi).

To list down available pdf files, use the given command:

 ls 

7. ls 3

Use the given command to compress your PDF file:

 gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed-file3.pdf e-Notes_PDF_All-Units_27042019042410AM.pdf 

8. screen

As you can see, we have used /screen for getting the highest compression and have renamed the output file to compressed-file3.pdf

Compressing PDF using GUI

If you are not comfortable using Terminal, we will show you how you can use compress your PDF using Densify. It is a GUI version of Ghostscript by which you can have the same functionality without messing with Terminal.

Step 1: Downloading and Installing Densify

Go to the official release page of Densify. Click on Code and select the Download ZIP option.

1. Downloading Zip

Open your File Manager and locate the Zip file of Densify. Right-click on Densify and select the option Extract here. You will see a new folder. Open that folder.

2. extracting

Right-click on space and select the Open in Terminal option. It will open the Terminal for the current directory.

3. opening termnal

Use the given command in Terminal:

 sudo chmod a+x install.sh 

4. sudo chmod a+x install

This command will install Densify on your system.

 sudo ./install.sh 

5. installing density

You will have to download Ghostscript to work with Densify. Use the given commands to download it:

 sudo apt install ghostscript 

2. sudo apt install Ghostscript

Step 2: Compressing PDF Files using Densify

Click on the Activities located at the top left corner and search for Densify. And open the first result.

6. finding densify in activities

Click on the little file icon to select your PDF file.

7. compressing

In type, you do have options such as:

The printer will get you a compressed PDF with 300 dpi

The ebook is known for balance between quality and compression with 150 dpi

The screen will avail you highest compression where quality is compromised a little with 72 dpi

Select the option accordingly and click on a compress. It will start the compression process

once the compression process is finished, you get a pop-up saying your file has been compressed and will also include the previous size and size after compression.

8. final result

Uninstalling Ghostscript and Densify

To remove Ghostscript from your system, use the given command:

 sudo apt purge ghostscript 

1. sudo apt purge ghostscript

To remove Densify, we have to delete the folder which we have extracted to install. Delete the folder. It will show you a warning. Click on Delete.

2. deleting folder

Open your terminal and use the given command to remove the logo of Densify from the menu:

 sudo rm /Densify/densify.desktop 

3. removing .desktop

Related Posts:

Wrapping up

In today’s tutorial, we learned to use Online compression and installed Ghostscript and Densify in Ubuntu to compress PDF files. By these methods, you can easily shrink your PDF files.

Default image
Sagar Sharma

Sagar always uses Linux to its core and loves to write the technical side of system administration! While he's not writing, you can always find him exploring new Linux distros!

Articles: 37