The major benefit of PDF documents is the intended representation remains almost same on any operating system or device. However, scanned PDFs can be of large sizes and you may need to optimize or reduce the size of the file to share it with a friend. This article discusses several ways to do that on Linux with near-original quality.
Native solutions
- Ghostscript is a great tool for compressing PDFs. In our tests it delivered the best compression ratio. Simply run:
$ gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=out.pdf in.pdf
-dPDFSETTINGS can be any of:
/screen : low-resolution output, lowest output size
/ebook : medium-resolution output, medium output size
/printer OR /prepress : high-resolution with maximum output size - Run the Shrinkpdf script:
$ ./shrinkpdf in.pdf out.pdf
The script is almost same as the explicit gs command above. However, it has one advantage – it does an output file size check.
- qpdf: A cmdline program that does structural, content-preserving changes to PDF files. The simplest way to invoke it:
$ qpdf --linearize input.pdf output.pdf
However, this didn’t provide a very optimized output in our tests.
To install qpdf on Ubuntu, run:$ sudo apt-get install qpdf
- smpdf is a commercial closed source tool. However, there is an evaluation copy available for download which adds an unlicensed version mark to the modified document. Usage:
$ smpdf in.pdf -o out.pdf
Also, convert to ps (pdftops) then back to pdf (ps2pdf) gets the jobs done as well
Not always. But it does work for for some files.
If you are only going to open it on Linux, at the very least evince can transparently open any of the common single-file compressed formats. For example, most of my collection is in pdf.xz. The specific advantage here is that it is loseless.
True, but the intention is to open the file anywhere.