LinuxCommandLibrary

ghostscript

Interpreter for PostScript and PDF file manipulation

TLDR

Convert PDF to images

$ gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r300 -sOutputFile=[page-%d.png] [input.pdf]
copy
Merge PDFs
$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=[merged.pdf] [file1.pdf] [file2.pdf]
copy
Compress PDF
$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=[small.pdf] [large.pdf]
copy
Convert PS to PDF
$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=[output.pdf] [input.ps]
copy
Extract pages from PDF
$ gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dFirstPage=[2] -dLastPage=[5] -sOutputFile=[extract.pdf] [input.pdf]
copy

SYNOPSIS

gs [options] [files]

DESCRIPTION

Ghostscript (gs) is an interpreter for PostScript and PDF. It renders documents to various output formats, converts between formats, and processes print jobs. It is the engine behind many PDF tools and print systems on Unix/Linux.
The tool supports a wide range of output devices for rasterization, format conversion, and print processing. PDF manipulation includes merging, splitting, compressing, and converting between quality levels.

PARAMETERS

-dNOPAUSE

Don't pause between pages.
-dBATCH
Exit after processing.
-sDEVICE device
Output device (pdfwrite, png16m, jpeg, etc.).
-sOutputFile file
Output filename (use %d for page numbers).
-r resolution
Resolution in DPI.
-dPDFSETTINGS setting
PDF quality: /screen, /ebook, /printer, /prepress.
-dFirstPage n
Start page.
-dLastPage n
End page.
-dCompatibilityLevel ver
PDF version (1.4, 1.5, etc.).

CONFIGURATION

/etc/ghostscript/

System-wide configuration directory for font mappings, resource files, and initialization scripts.
~/.ghostscript
User-specific Ghostscript resources and configuration overrides.

CAVEATS

Complex command-line syntax. Some operations require specific device drivers. Font handling may need configuration. Security settings restrict file operations.

HISTORY

Ghostscript was started by L. Peter Deutsch in 1988 as a free PostScript interpreter. It's now developed by Artifex Software and remains fundamental to Unix/Linux printing and PDF processing.

SEE ALSO

pdf2ps(1), ps2pdf(1), pdftk(1), convert(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community