PDF is the abbreviation of Portable Document File, frequently used by users for sharing information related to work or anything. Sometimes, the PDF file size gets large when scanned, which takes a lot of time to upload or share. Is there any way to reduce the size of the PDF file without influencing its content? Yes! There are various ways to perform that operation in Linux.
This post will demonstrate the methods to reduce the file size of PDF files in Linux.
- Method 1: Through Ghostscript (gs)
- Method 2: Through ps2pdf
- Method 3: Thorough Online Compressor Tool
Method 1: Through Ghostscript (gs)
The ghostscript is the utility of Linux that facilitates the user to reduce any file size. So this tool can be used to reduce the PDF file size.
To install the Ghostscript on Linux, run the below-mentioned command per the Linux distribution:
$ sudo apt install ghostscript #For Debian/Ubuntu $ sudo yum install ghostscript #For Fedora/CentOS/RHEL
The “ghostscript” has been installed.
$ gs [switches] [PDF File]
Use the “gs” keyword, describe the switches (properties of Ghostscript), and the PDF file name.
Let’s implement an example using the above syntax:
Example: Reduce File Size of PDF File
Check the original file size of the PDF file using the “ls” command with the “s” and “h” flags:
$ ls -sh
The original file size is 14MB.
To compress the file size through the “gs” utility, use the below command along with the given attributes, and specify the file name at the end:
$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf scanned.pdf
The new file with the name “output.pdf” will be created.
The attributes are described in the following table:
|“sDEVICE=pdfwrite”||Detects the output device “pdfwrite”.|
|dCompatibilityLevel=1.4||Convert the file to the compatibility level of 1.4.|
|dPDFSETTINGS=/screen||Generate the smaller size and lower quality.|
|“dNOPAUSE” and “dBATCH”||Both options disable the interruptions|
|dQUIET||Run in the quiet/silent mode.|
|sOutputFile=output.pdf”||Generates output file.|
“dPDFSETTINGS” Option Table
Furthermore, the “dPDFSETTINGS” has the options that can be used accordingly:
|-dPDFSETTINGS=/screen||It generates the low-level resolution PDF files. (72dpi).|
|-dPDFSETTINGS=/prepress||It generates a high-level resolution PDF file (300 dpi).|
|-dPDFSETTINGS=/printer||It generates high quality for printers (300 dpi).|
|-dPDFSETTINGS=/default||It generates a larger file size but a high-quality image.|
|-dPDFSETTINGS=/ebook||It generates better quality but is a bit large in size (150dpi).|
Check the directory and file size of the “output.pdf” file:
$ ls -sh
The file size has been reduced from 14MB to 200KB.
Method 2: Through ps2pdf
The “ps2pdf” comes with the installation of the ghostscript (gs) utility, it converts the files from PS format to PDF format and compresses them. The user can use this utility to compress the PDF File, the syntax for the “ps2pdf” utility is given below:
$ ps2pdf [Options] [Input File] [Output File]
Use the “ps2pdf” keyword, “options” along with the command, and specify the input, output file name.
The below example is the representation of the above syntax.
To reduce the file size using the “ps2pdf” file is obtained as follows:
$ ps2pdf -dPDFSETTINGS=/ebook scanned.pdf output2.pdf
The file size has been reduced. Here, the “-dPDFSETTINGS=/ebook” option is for the best size and quality of the file.
Check the file size in the directory using the “ls” command:
The above image shows that the file size has been reduced from 14MB to 464KB.
Method 3: Thorough Online Compressor Tool
Another way to reduce the file size is using the online PDF compressor tool; go through the following steps to utilize it:
Step 1: Access the Tool and Browse the File
Open your favorite web browser and access the PDF Compressor website. After that, browse the file PDF file to compress:
Step 2: Compress the File
After selecting the file, choose the compression option from the given compression levels, such as high, medium, and low:
- High: Compress the file with standard quality and the smallest size.
- Medium: Compress the file with a better quality medium file size.
- Low: Compress the file, giving the highest quality with a larger size.
The file will be compressed, and the user will receive the successful notification of reduced file size:
The file size has been reduced from 13.49MB to 132.98KB.
Step 3: Download the Compressed File
Download the compressed file by clicking on the “Download” option:
The compressed file will be downloaded.
To reduce the file size of the scanned PDF, use the command line utilities ghostscript (gs) and “ps2pdf” or utilize the PDF online compression tool. The ghostscript (gs) can be installed through the given command, which also installs the “ps2pdf” utility. While the online compression tool offers online support to reduce the size of a scanned PDF. This write-up has illustrated methods to reduce the file size of the scanned PDF file.