how to reduce pdf file size in linux using ghostscript | Compress PDF file size with ghostscript gs

preview_player
Показать описание
compress pdf files with ghostscript
#compress #pdf #ghostscript

Reduce pdf file size with GhostScript pdf compression under Linux/Unix

how to reduce pdf file size in linux using ghostscript ?

Using Ghostscript options (/screen, /ebook, /printer, /prepress) can reduce files to ~15% of their size, with no obvious degradation of quality (from ebook - printer - prepress).
thanks to ghostscript option '/ebook ' that works perfect , big difference in size and marginal difference in quality.

GNU Ghostscript is a free open-source interpreter for the PostScript language and the PDF file format. It is distributed under the GNU General Public License.

The above command should work on Windows and OS X as well, as long as Ghostscript is installed.

PDF version 1.5 seems to feature a better image compression. I should look into that more closely.

Do you use a different method to reduce PDF files? Let us know in the comments how you do it.

Other Ghostscript options for PDFSETTINGS:

/screen selects low-resolution output similar to the Acrobat Distiller "Screen Optimized" setting.
/ebook selects medium-resolution output similar to the Acrobat Distiller "eBook" setting.
/printer selects output similar to the Acrobat Distiller "Print Optimized" setting.
/prepress selects output similar to Acrobat Distiller "Prepress Optimized" setting.
/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file.

What we are interested in, is the gs (ghostscript) command line tool, which provides many options for manipulating PDF, but we are interested in compressign those large PDF's into small yet legible documents.

Reduce PDF File Size With Ghostscript : sometimes people will ask me how to reduce PDF file size, so it’s clearly a topic of interest.
* As I mentioned, this tip is extremely geeky and involves scripting and a command shell (aka the Terminal on macOS). If you’re not comfortable with that, you may want to give this one a pass and use something like Adobe Acrobat or macOS Preview.
* This tip uses a Unix tool called Ghostscript. I’ll be showing the tip on the Mac, and the page I linked to above is for Linux. There is a version of Ghostscript on Windows, but I am not sure if this tip will work with it.

Once you have Homebrew installed, install Ghostscript by going to Terminal and typing:

brew install ghostscript

Homebrew will do its magic, and you should be good to go.

I tried using screen for PDFSETTINGS, but the result looked awful. For me, ebook did the trick. There’s a tiny (to my eyes) reduction in quality, but for most of my scanned PDFs the file size was reduced quite a bit.

As a result, here’s the script that I’ve been using:

or

The parameters in detail
-sDEVICE=pdfwrite selects which output device Ghostscript should use. I want to print to a PDF file, so I'm using pdfwrite.

-dCompatibilityLevel=1.4 generates a PDF version 1.4. You may want to change this according to your needs. Here's a list of all PDF versions.

-dPDFSETTINGS=/printer sets the image quality for printers (i.e. 300 dpi). Choose /screen if you want to scale it down to 72 dpi: you will obtain additional compression (but the file will look ugly if printed on paper).

-dPDFSETTINGS= specifies the quality level of the pdf file. This effects embedded pixel graphics (also adapts embedded color profiles) and is the main option for controlling the compression level, thereby the resulting file size:

-dPDFSETTINGS=/screen (72 dpi images)
-dPDFSETTINGS=/ebook (150 dpi images)
-dPDFSETTINGS=/printer (300 dpi images)
-dPDFSETTINGS=/prepress (300 dpi images, color preserving)
-dPDFSETTINGS=/default

-dBATCH -dNOPAUSE: Ghostscript will process the input file(s) without interaction. It will quit on completion.

-dQUIET mutes routine information comments on standard output.

-sProcessColorModel=DeviceGray is the color model to use during conversion.

-sColorConversionStrategy=Gray instructs Ghostscript to produce a grayscaled output.

-dOverrideICC: since the color has changed, -dOverrideICC updates the color profile accordingly.

Рекомендации по теме