GhostScript

You are here:

Table of Contents

What Is it?

Ghostscript is an interpreter for the PostScript®  language and PDF files. It is available under either the GNU GPL Affero license or  licensed for commercial use from Artifex Software, Inc. It has been under active development for over 30 years and has been ported to several different systems during this time. Ghostscript consists of a PostScript interpreter layer and a graphics library. [1]

Install

OS specific instructions on how to install can be found at the official api documentation [2]

Usage

With Ghostscript you can control the intensity of compression using the -dPDFSETTINGS parameter. The -dPDFSETTINGS flag defines the level of quality and compression applied to the output PDF, ranging from very high compression (but lower quality) to minimal compression (retaining high quality).

Options

The available -dPDFSETTINGS options that control the compression intensity are the following:

PDFSETTINGS Options:

• /screen: Low-resolution output (72 dpi), highly compressed. Suitable for on-screen viewing, not for printing.

• /ebook: Medium-resolution output (150 dpi), suitable for e-books and good-quality on-screen viewing.

• /printer: Higher-resolution output (300 dpi). Suitable for printing but with some compression to reduce file size.

• /prepress: Maximum resolution and minimal compression (maintains 100% quality). This is ideal for professional printing.

• /default: Uses the default settings of Ghostscript, which are balanced between size and quality.

Application

High compression for small file sizes, low image quality:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Medium Compression for E-Books:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

High Quality (Good for Printing):

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Minimal Compression (Best Quality for Professional Printing):

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.5 -dPDFSETTINGS=/prepress -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Flags

you can manually specify the image quality by adjusting these flags in your Ghostscript command:

• Downsampling images:

• -dColorImageDownsampleType=/Bicubic

• -dColorImageResolution=150 (or other values, like 72 or 300, depending on the desired resolution)

• -dGrayImageDownsampleType=/Bicubic

• -dGrayImageResolution=150

• -dMonoImageDownsampleType=/Subsample

• -dMonoImageResolution=300

References

[1] https://www.ghostscript.com

[2] https://ghostscript.readthedocs.io/en/latest/Install.html

Related content

Leave a Reply