ghostscript
Interpret and render PostScript and PDF documents
SYNOPSIS
gs [-options] [files ... ]
PARAMETERS
-dBATCH
Exit after last file, no user interaction
-dNOPAUSE
Disable pause between pages
-dQUIET
Suppress routine startup messages
-dSAFER
Sandbox mode, restricts file access for security
-dNOPROMPT
Disable interactive prompts
-sDEVICE=device
Set output device, e.g., pdfwrite, png16m, x11
-sOutputFile=file
Specify output filename (%%stdout for stdout)
-rres
Set resolution in DPI, e.g., -r300
-dFirstPage=n
Start processing from page n
-dLastPage=n
Process up to page n
-dAutoRotatePages=/mode
Control page rotation, e.g., /PageByPage
-sPAPERSIZE=size
Set paper size, e.g., a4, letter
-Idirs
Add directories to search path for fonts/resources
-c code
Execute PostScript code snippet
-f
Interpret following files as PostScript
DESCRIPTION
Ghostscript (typically invoked as gs) is a powerful open-source interpreter for PostScript (PS) and PDF files, capable of rendering, converting, and manipulating these formats on Unix-like systems including Linux.
It processes PS and PDF documents to produce output in various formats such as PDF, PNG, JPEG, TIFF, or directly to printers. Ghostscript emulates the full Adobe PostScript language, supporting Level 1 through 3, and handles PDF 1.0 to 2.0.
Common uses include converting PS to PDF (ps2pdf wrapper), viewing files interactively, distilling PDFs for optimization, or generating raster images. It features a high-level device interface for output devices, color management, font embedding, and scripting via PostScript.
Developed for robustness, it runs complex graphics jobs but requires careful handling of memory and security options like -dSAFER for untrusted inputs to prevent exploits. Widely used in printing workflows, document processing, and tools like CUPS.
Ghostscript excels in batch processing with options for quiet operation, no pauses, and custom resolutions, making it essential for server-side PDF handling.
CAVEATS
Resource-intensive for large files; use -dSAFER with untrusted inputs to mitigate vulnerabilities. Deprecated devices may be removed in future versions. Not all PDF features (e.g., PDF 2.0 subsets) fully supported.
COMMON DEVICES
pdfwrite (PDF output), pngalpha (PNG), jpeg, tiff24nc, x11 (screen display), lpr (printer). List via gs -h.
QUICK EXAMPLE
Convert PS to PDF: gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf in.ps
View PDF: gs -dSAFER in.pdf
WRAPPERS
Tools like ps2pdf, pdf2ps are scripts calling gs with predefined options.
HISTORY
Ghostscript originated in 1988 by Thomas and L. Peter Deutsch as a PostScript interpreter for non-Adobe systems. Released publicly in 1989, it gained popularity for Unix printing. Version 9.0 (2012) added PDF 1.7 support; now at 10.x under Artifex Software (AGPL/commercial licenses). Widely used in GhostPDL suite.


