Compressing PDF files can be useful for reducing their size, making them easier to share or upload. Here are some methods to compress PDF files using command-line tools on Linux:
Using gs (Ghostscript)
gs is a powerful tool for manipulating PDFs. You can install it on most Linux distributions.
Installation:
- On Ubuntu/Debian and derivatives:
sudo apt update
sudo apt install ghostscript
- On Fedora:
sudo dnf install ghostscript
- On Arch Linux/Manjaro:
sudo pacman -S ghostscript
Compressing PDF:
To compress a PDF, you can use the following command:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
This command compresses the PDF using the screen settings, which is suitable for web viewing. You can adjust the compression level by changing the -dPDFSETTINGS option to one of the following:
/screen: Low resolution, suitable for web viewing
/ebook: Medium resolution, suitable for e-books
/printer: High resolution, suitable for printing
/prepress: Very high resolution, suitable for pre-press
Using pdfsizeopt
pdfsizeopt is a tool specifically designed for compressing PDFs.
Installation:
- On Ubuntu/Debian and derivatives:
sudo apt update
sudo apt install pdfsizeopt
- On Fedora:
sudo dnf install pdfsizeopt
- On Arch Linux/Manjaro:
sudo pacman -S pdfsizeopt
Compressing PDF:
To compress a PDF, you can use the following command:
pdfsizeopt input.pdf output.pdf
This command compresses the PDF using the default settings. You can adjust the compression level by using the -s option, followed by a number from 0 (no compression) to 9 (maximum compression).
Using qpdf
qpdf is another tool that can be used to compress PDFs.
Installation:
Compressing PDF:
To compress a PDF, you can use the following command:
qpdf --compress-level=9 input.pdf output.pdf
This command compresses the PDF using the maximum compression level (9). You can adjust the compression level by changing the number after --compress-level.
These are just a few examples of how you can compress PDF files using command-line tools on Linux. The choice of tool depends on your specific needs and preferences.