Ghostscript is one of the oldest, most widely-used, and most powerful tools in the PDF ecosystem. It is the engine that drives countless print pipelines, document conversions, and PDF manipulations across Linux, macOS, and Windows. If you have ever processed PDFs in any kind of automated way, there is a good chance Ghostscript was somewhere in the pipeline. This guide is an introduction: what it is, what it does, and how to use it.
What Ghostscript is
Ghostscript is a free, open-source interpreter for PostScript and PDF. Originally created in 1986 by L. Peter Deutsch, it has been maintained by Artifex Software since the late 1990s. It is available under both open-source (AGPL) and commercial licenses.
Functionally, Ghostscript can:
- Convert PostScript to PDF
- Convert PDF to PostScript
- Render PDFs to raster images (PNG, JPEG, TIFF)
- Manipulate PDFs (combine, split, compress, encrypt)
- Convert between PDF versions
- Embed and substitute fonts
- Apply color management
Almost every "print to PDF" feature on Linux, and many on Windows and macOS, runs through Ghostscript under the hood.
Installing Ghostscript
Linux:
sudo apt install ghostscript # Debian / Ubuntu
sudo dnf install ghostscript # Fedora
sudo pacman -S ghostscript # Arch
macOS:
brew install ghostscript
Windows:
Download installer from ghostscript.com and run.
After installation, the gs command (Linux/Mac) or gswin64c (Windows) is available.
The basic command structure
gs [options] [-o output_file] [-sDEVICE=device_name] input_file(s)
-o output.pdf, output file-sDEVICE=pdfwrite, set the device (controls output format)-dNOPAUSE -dBATCH, non-interactive run
These flags appear in nearly every command. The variety of operations comes from different devices and parameters.
Common operations
Combine PDFs:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile=combined.pdf file1.pdf file2.pdf file3.pdf
Compress / reduce file size:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dPDFSETTINGS=/ebook \
-sOutputFile=smaller.pdf input.pdf
PDFSETTINGS values:
/screen, 72 DPI, smallest files, low quality/ebook, 150 DPI, good for screens/printer, 300 DPI, good for print/prepress, 300 DPI with color management, professional print/default, typically same as/screen
See reduce PDF file size.
Convert PDF to image (PNG):
gs -dNOPAUSE -dBATCH -sDEVICE=png16m -r150 \
-sOutputFile=page-%d.png input.pdf
-r150 sets 150 DPI. -sDEVICE=png16m produces 24-bit RGB PNG.
See how to convert a PDF to image.
Convert PDF to multi-page TIFF (G4 fax compression):
gs -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -r300 \
-sOutputFile=output.tif input.pdf
See how to convert a PDF to TIFF.
Convert PostScript to PDF:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-sOutputFile=output.pdf input.ps
Convert PDF to PostScript:
gs -dNOPAUSE -dBATCH -sDEVICE=ps2write \
-sOutputFile=output.ps input.pdf
Extract page range:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dFirstPage=5 -dLastPage=10 \
-sOutputFile=pages-5-10.pdf input.pdf
Linearize for fast web view:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dFastWebView=true \
-sOutputFile=fast.pdf input.pdf
See linearized PDF and fast web view.
Encrypt with password:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dEncryptionR=6 -dKeyLength=256 \
-sUserPassword=user_pw -sOwnerPassword=owner_pw \
-sOutputFile=encrypted.pdf input.pdf
See how to password protect a PDF and AES-128 vs AES-256 PDF encryption.
Convert PDF to PDF/A:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dPDFA=2 -dPDFACompatibilityPolicy=1 \
-sColorConversionStrategy=RGB \
-sOutputFile=archive.pdf input.pdf
See PDF/A archival format explained.
Working with fonts
Ghostscript handles font substitution automatically:
- Looks up fonts in the PDF's embedded font dictionary
- Falls back to system fonts if a font is referenced but not embedded
- Can embed system fonts on output for portability
For font-troublesome PDFs:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dEmbedAllFonts=true -dSubsetFonts=true \
-sOutputFile=output.pdf input.pdf
Forces all fonts to be embedded and subsetted in the output.
Color management
For color-critical work:
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
-dPDFSETTINGS=/prepress \
-sColorConversionStrategy=CMYK \
-dProcessColorModel=/DeviceCMYK \
-sOutputFile=cmyk.pdf input.pdf
Converts the output to CMYK with prepress quality. See CMYK vs RGB in PDF and color management in PDF.
Batch operations
Ghostscript shines at scripting. Common patterns:
# Compress all PDFs in a folder
for f in *.pdf; do
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook \
-sOutputFile="compressed/$f" "$f"
done
# Convert all PDFs to TIFF
for f in *.pdf; do
gs -dNOPAUSE -dBATCH -sDEVICE=tiffg4 -r300 \
-sOutputFile="tiff/${f%.pdf}.tif" "$f"
done
Parallelize with xargs -P N or GNU parallel for large batches.
Combining with other tools
Ghostscript is one piece of a Linux PDF toolchain. Common partners:
- qpdf for structural operations (split, merge, encryption). See qpdf introduction.
- pdftk for forms and stamps. See pdftk introduction.
- poppler-utils for text extraction and conversion. See poppler-utils introduction.
- MuPDF / mutool for fast rendering. See MuPDF introduction.
- ImageMagick for image-side processing.
- ExifTool for metadata. See how to edit PDF metadata.
Pipelines often chain these tools: extract text with pdftotext, process with shell scripts, recombine with Ghostscript, encrypt with qpdf.
Verbosity and debugging
Ghostscript can be quiet or verbose:
-q, quiet mode, suppress output-dQUIET, same as-q-dPDFDEBUG, extensive PDF parsing debug info-dGRAPHICSALPHABITS=4 -dTEXTALPHABITS=4, better anti-aliasing for raster output
For debugging weird PDFs, the verbose modes are invaluable.
Performance considerations
Ghostscript performance varies by operation:
- Rendering is CPU-intensive; uses multiple cores for some devices
- Compression depends heavily on input image data
- Conversion to PostScript is slow for complex PDFs
- Combining many small PDFs is fast; combining huge PDFs uses lots of memory
For high-throughput pipelines, profile the specific operation on representative input.
Common gotchas
Permissions / restricted PDFs. Ghostscript may refuse to process encrypted PDFs without a password. Provide via -sPDFPassword=....
Image quality on compression. Default -dPDFSETTINGS=/ebook may downsample images aggressively. Use /printer or /prepress for higher quality.
Color shifts during conversion. Color management is complex; conversion may produce visible shifts. Verify on a test sample.
Font embedding warnings. Ghostscript may warn about font embedding issues. Check the output renders correctly.
File size larger than input. Some operations (like re-rendering) can increase file size. Use compression flags.
Linearization. -dFastWebView=true does not always succeed; some PDFs cannot be linearized. Check the result.
Memory usage on huge PDFs. Very large PDFs (thousands of pages) may exceed memory limits. Process in batches.
Version compatibility. Ghostscript 9.x and 10.x have some flag differences. Check the version of your installation.
License. Ghostscript is under AGPL; using it in proprietary commercial software requires a commercial license from Artifex.
When to reach for Ghostscript
- You have a Linux pipeline that needs PDF processing
- You want maximum control over compression, color, fonts
- You need to convert between PDF and PostScript (rare today but real)
- You are integrating with a print system that talks PostScript natively
- You want a portable, scriptable, well-documented tool for PDF manipulation
For interactive editing, GUI tools are easier. For batch processing and pipelines, Ghostscript is hard to beat.
Takeaway
Ghostscript is the foundational CLI tool for PDF and PostScript manipulation on Unix-like systems. It does compression, conversion, encryption, merging, rendering, and more, all through a unified command-line interface. The learning curve is real (the command flags can feel cryptic), but the payoff in automation power is enormous. For interactive workflows, pair it with Docento.app for quick browser-based operations and reach for Ghostscript when scripts and pipelines need to do work at scale. For related CLI tools, see qpdf introduction, pdftk introduction, poppler-utils introduction, and MuPDF introduction.