Compress PDF File in Ubuntu - Step by Step Process ?

PDFs offer us one of the most convenient ways of sharing images. 

However, by stuffing tons of data such as images and graphics, the PDF file size can get too big to share via emails.

If you are also suffering from this issue, you have come to the right place.

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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform related Linux queries.

In this context, we shall look into how to compress PDF file without compromising with data in it on Ubuntu.


How to Compress PDF Files Using Command Line Method on Ubuntu ?

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

Below are the -dPDFSETTINGS options, which you can use according to your need:

i. -dPDFSETTINGS=/screen: for lower quality and smaller size output.

ii. -dPDFSETTINGS=/ebook: better quality with slightly larger file size.

iii. -dPDFSETTINGS=/prepress: high quality output and size.

iv. -dPDFSETTINGS=/printer: output ideal for printer quality.


[ Need urgent Linux related support ? We can help you. ]

This article covers how you can compress the PDF file size in Linux and its distributions like Ubuntu. 

Although applications like LibreOffice Writer allow you to convert your business documents into portable and secure PDFs, sometimes the files they produce are too large and unwieldy. These huge files may hog network bandwidth, waste space on company storage devices or be too big to share as email attachments. 

Fortunately, Ubuntu provides a complicated, but efficient method to reduce the size of your PDFs using the standard Ghostscript library of command line utilities.


How to use Ghostscript command to compress PDF file in Linux Systems ?

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

1. Start a Ubuntu terminal session and navigate to the folder containing the PDF file you want to shrink.

2. PDF is in the Documents folder, type "cd Documents" (without the quotation marks) at the terminal prompt and press "Enter."

3. Type the Ghostscript command to reduce the size of your PDF file. For example, if your file is named "mydoc.pdf" and you want the reduced version to be called "mydocsmaller.pdf," type the following command at the terminal prompt as a single line:

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

This command instructs the Ghostscript GS utility to take the file "mydoc.pdf" and create a version 1.4-compatible, low-resolution PDF file called "mydoc_smaller.pdf" that is optimized to be displayed on your PC screen rather than printed on paper.

Related Posts