Compress a PDF with Linux
From time to time I happened to draw up illustrative documents to be delivered in PDF. It goes without saying that by containing every type of image and illustration, the PDF ended up weighing several MB.
One of the solutions I initially adopted was to use an online PDF compression service. There are all types of both paid and free, but I never liked it as a solution and having to depend on someone else's computer doesn't do much for me, so i searched a bit’ deeper and I found some interesting solutions which I summarize in this article.
Method #1: the command line
Using the terminal is always a good idea when you know what you're doing and want to avoid the frills. The functionality we seek is in the package
ghostscript, a package already present in most distributions “standard”, and in any case certainly present in the repositories.
This syntax will reduce the size of the PDF:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=compressed_PDF_file.pdf input_PDF_file.pdf
The command seems long and complicated, and in reality these options should work for most practical applications. The most important variable (the one that more than the others will determine the size of the final file) is
|/prepress (default)||Better quality, 300dpi, higher weight|
|/ebook||Medium quality, 300dpi, moderate weight|
|/screen||Lower quality, 72dpi, the lightest|
Note that some PDFs cannot be compressed at all, or after having made the compression they can be even heavier. In those rare special cases there is not much to do.
Method #2: the graphic interface
Of course not everyone likes to deal with the terminal. Linux boasts a large number of programs that can do a few things. In short it is not possible to create an already lightweight PDF with a native program, or an integrated function, but using one second we could achieve the result.
Unfortunately, among the GUI there is not even an updated solution on linux. The only GUI (which apparently relies on ghostscript) is Densify.
Installation is quite simple. Official GitHub, download of the program in ZIP format, unpacking, attribution of permits
a+x al file
install.sh and start the file.
Once Densify is started it will ask you to enter the path to the source file, the name of the desired destination file, the final support (and relative compression).
Personally I am better off with the command line. And you?