Compress pdf files using Ghostscript in Linux

Original link: https://blog.kelu.org/tech/2022/07/25/linux-command-for-pdf-compress.html

Install

Most Linux distributions already include an open source version of Ghostscript. If not, install it as follows:

 apt install ghostscript

use

Suppose I want to compress the file编程珠玑.pdf :

 /usr/bin/gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -dColorImageResolution=150 -sOutputFile=编程珠玑_compressed.pdf 编程珠玑.pdf

Regarding the compression quality, we only need to modify the dPDFSETTINGS parameter:

dPDFSETTINGS describe
/prepress (default) High quality (300 dpi) but larger files
/ebook Medium quality (150 dpi) moderate file size
/screen Low quality (72 dpi) but smaller output file

The ebook is more suitable in terms of file size and clarity, so I use it. Compressed by about 40%.

image-20220725102425521

Refer to the Ghostscript online documentation for more parameters.

This article is reprinted from: https://blog.kelu.org/tech/2022/07/25/linux-command-for-pdf-compress.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment