GSview: A Complete Beginner’s Guide to Viewing PS and PDF Files

Advanced Tips: Optimizing PDFs with GSview and GhostscriptPDF optimization helps reduce file size, improve rendering performance, and make documents easier to share. When working with PostScript (PS) and PDF files, GSview (a graphical front-end) paired with Ghostscript (the command-line interpreter and processing engine) provides a powerful toolkit for optimization. This article covers advanced techniques for reducing size, improving compatibility, and preserving quality using GSview and Ghostscript—plus best practices, examples, and troubleshooting tips.


Overview: GSview and Ghostscript roles

GSview provides a graphical interface to view and perform some operations on PostScript and PDF files. Ghostscript is the underlying engine that actually interprets, converts, and manipulates PS/PDF content via command-line options. Many advanced optimizations are done by invoking Ghostscript directly; GSview can make previewing and simpler operations easier.


Before you start: analyze the PDF

  1. Determine what’s inflating the file size:

    • Embedded images (high resolution, uncompressed formats).
    • Fonts (many subsets or fully embedded fonts).
    • Excessive metadata, annotations, or unused objects.
    • Scanned pages stored as full-resolution images without compression.
  2. Tools to inspect:

    • GSview to preview and inspect pages.
    • Ghostscript’s conversion output (verbose) to detect issues.
    • PDF inspection tools (pdfinfo, qpdf, or commercial PDF editors) to list fonts, images, and objects.

Basic Ghostscript command structure

Most advanced PDF work uses Ghostscript’s pdfwrite device. The canonical form:

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

Key flags:

  • -sDEVICE=pdfwrite — use Ghostscript’s PDF writer.
  • -dCompatibilityLevel=1.4 — target PDF version (1.4 is broadly compatible).
  • -dPDFSETTINGS — preset quality/compression; see below.
  • -dNOPAUSE -dBATCH -dQUIET — batch-mode controls.

Understanding -dPDFSETTINGS presets

Ghostscript includes several PDFSETTINGS presets that balance size vs. quality:

  • /screen — lowest quality, smallest size (72 dpi images).
  • /ebook — medium quality (150 dpi).
  • /printer — high quality (300 dpi).
  • /prepress — preserves color and resolution for professional printing (similar to printer but keeps more image data).
  • /default — a sensible general-purpose setting.

Use these presets as a starting point and refine other parameters for fine control.


Advanced image handling

Images are often the largest component of a PDF. Control how Ghostscript resamples, compresses, and encodes images.

  • Control downsampling and interpolation:
    • -dDownsampleColorImages=true|false
    • -dDownsampleGrayImages=true|false
    • -dDownsampleMonoImages=true|false
    • -dColorImageDownsampleType=/Bicubic or /Average or /Subsample
    • -dColorImageResolution=150 (target DPI)

Example: downsample color images to 150 DPI using bicubic resampling:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4     -dDownsampleColorImages=true -dColorImageDownsampleType=/Bicubic     -dColorImageResolution=150     -sOutputFile=out.pdf in.pdf 
  • Choose compression:
    • For continuous-tone images: /DCTEncode (JPEG) is common.
    • For images requiring lossless: /FlateEncode (ZIP) or keep as-is.
    • Options:
      • -dEncodeColorImages=true
      • -dEncodeGrayImages=true
      • -dAutoFilterColorImages=true (lets Ghostscript pick)

To force JPEG encoding and control quality:

-dAutoFilterColorImages=false -dEncodeColorImages=true -sColorImageFilter=/DCTEncode -dJPEGQ=85 
  • Mono images (scans of black-and-white text) can use CCITT Group 4 compression for great size reduction:
    • -dMonoImageFilter=/CCITTFaxEncode

Font optimization

Embedded fonts can bloat PDFs. Strategies:

  • Subset fonts rather than fully embed them (Ghostscript subsets by default). Keep default behavior unless full embedding required.
  • Replace embedded fonts with standard PDF fonts (Times, Helvetica) when acceptable to reduce size and ensure wide compatibility.
  • Convert text to outlines is possible but usually increases size and eliminates selectable/searchable text—avoid unless necessary.

Ghostscript options influencing fonts:

  • -dSubsetFonts=true
  • -dEmbedAllFonts=true or false (set false to avoid embedding; use cautiously)
  • -sFONTPATH=… to provide substitute fonts

Example: prefer system fonts and subset:

gs -sDEVICE=pdfwrite -dSubsetFonts=true -dEmbedAllFonts=false -sFONTPATH="/usr/share/fonts" -sOutputFile=out.pdf in.pdf 

Color space and transparency

  • Convert colors to a device-independent space (e.g., RGB or grayscale) if appropriate:
    • -sColorConversionStrategy=/sRGB or /Gray
    • -dProcessColorModel=/DeviceRGB or /DeviceGray

Example: convert to sRGB to standardize color profiles:

gs -sDEVICE=pdfwrite -dColorConversionStrategy=/sRGB -dProcessColorModel=/DeviceRGB -sOutputFile=out.pdf in.pdf 
  • Flatten transparency if some PDF viewers struggle with complex blending—Ghostscript flattens when writing to older compatibility levels, but you can explicitly target a lower compatibility level.

Removing unnecessary objects and metadata

  • Strip metadata and annotations to reduce size and remove private data:
    • -dDetectDuplicateImages=true (avoid duplicate storage)
    • Use external tools (qpdf, exiftool, or a PDF editor) to remove metadata if Ghostscript options insufficient.

Ghostscript doesn’t have a single switch that strips all metadata, but rewriting with pdfwrite often drops unused objects.


Combining and linearizing PDFs (for web)

  • Combine PDFs: use Ghostscript to concatenate pages into a single optimized file by listing multiple inputs.
  • Linearize (also called “web optimize” or “fast web view”) makes PDFs streamable over HTTP. Ghostscript historically did not produce perfectly linearized PDFs reliably; use qpdf for linearization after Ghostscript processing:

Example: optimize with Ghostscript then linearize with qpdf:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -sOutputFile=tmp.pdf in.pdf qpdf --linearize tmp.pdf optimized-linearized.pdf 

Automating workflows and batch processing

  • Wrap Ghostscript commands in shell scripts or Makefile targets to process many files with consistent settings.
  • For large document libraries, keep separate profiles (e.g., high-quality, web, archival) encoded as script flags or small config files.

Example bash snippet to process all PDFs in a folder:

for f in *.pdf; do   gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook       -dNOPAUSE -dBATCH -dQUIET -sOutputFile="opt_${f}" "$f" done 

Use GSview for previewing and quick tweaks

  • Use GSview to inspect pages after Ghostscript processing to check visual fidelity.
  • GSview can show both the original and optimized versions side-by-side; use it to confirm image quality, fonts rendering, and page layout.

Troubleshooting common issues

  • Text becomes garbled after optimization:
    • Check font embedding/subsetting settings.
    • Try embedding fonts fully (-dEmbedAllFonts=true) to diagnose.
  • Loss of image quality:
    • Increase -dColorImageResolution or choose /printer instead of /ebook.
    • Raise -dJPEGQ (0–100).
  • Large output despite settings:
    • Check for many embedded fonts, high-resolution images, or scanned pages stored as uncompressed images.
    • Use -dDetectDuplicateImages=true to avoid duplicate image streams.
  • Compatibility problems with specific viewers:
    • Try different -dCompatibilityLevel values (1.4, 1.5, 1.6).
    • Avoid advanced features like transparency when targeting older viewers.

Example advanced command

A balanced command that down-samples images to 150 DPI, uses JPEG with decent quality, subsets fonts, and targets good compatibility:

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4     -dPDFSETTINGS=/printer     -dDownsampleColorImages=true -dColorImageResolution=150 -dColorImageDownsampleType=/Bicubic     -dDownsampleGrayImages=true -dGrayImageResolution=150     -dAutoFilterColorImages=false -dEncodeColorImages=true -sColorImageFilter=/DCTEncode -dJPEGQ=85     -dSubsetFonts=true -dEmbedAllFonts=false     -dDetectDuplicateImages=true     -dNOPAUSE -dBATCH -dQUIET     -sOutputFile=optimized.pdf input.pdf 

When not to aggressively optimize

  • Archival or master copies: preserve originals at full quality and store optimized versions separately.
  • Documents requiring exact print fidelity (fine-art reproduction, prepress) should use conservative settings (/prepress) or avoid downsampling.
  • Legal or accessibility documents where text searchability must remain intact—avoid converting text to images or outlines.

Final checklist before distribution

  • Compare file sizes (original vs optimized).
  • Visually inspect key pages in GSview and multiple PDF viewers (Adobe Reader, browser viewers).
  • Verify searchable/selectable text remains if needed.
  • Confirm fonts render correctly on target systems.
  • Linearize if intended for web delivery.

Optimizing PDFs with GSview and Ghostscript gives you fine-grained control over file size, quality, and compatibility. Start with presets, inspect results, then tweak image, font, and color settings iteratively. Keep originals untouched and automate repeatable workflows for consistent results.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *