Using GhostScript for Microsoft Windows

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 10:21, 31 December 2014 by Admin (Talk | contribs)

Jump to: navigation, search

Command Line. Ghostscript is a suite of software. You can view, convert, and manipulate PDF files. Ghostscript is an interpreter for PostScript and Portable Document Format (PDF) files. Postscript can be picky and inconsistent about the PDF files it will open.

Example: view a PDF on Windows XP

gswin32c.exe -dSAFER -dBATCH "C:\Program Files\GPLGS\test3.pdf"

The example will open the pdf document in a GUI window for viewing.

To execute ghostscript on a *nix system the command is "gs" while on a Windows system it is one of the gswin*.exe variants depending on the compiler source and your PC architecture.

Usage Examples

Put multiple pdf files to one combined output

gs -sDEVICE=pdfwrite -dNOPAUSE -dBATCH -dSAFER -sOutputFile=combined.pdf in1.pdf in2.pdf in3.pdf 

Rendering Postscript to a raster image (ppmraw)

gs -sDEVICE=ppmraw -q -sOutputFile=- -r600 input.ps < /dev/null

Force embed the fonts in output: To put all fonts in your PDF in as compatible a form as possible, use the options "-dSubsetFonts=false -dEmbedAllFonts=true" (with ps2pdf or any other Ghostscript-based PDF generator).

Normalize a PDF: convert a generic PDF file to a normalized PDF file

gs -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress -sOutputFile=output.pdf input.pdf

gswin32c.exe error occured while reading xref table

Ghostscript PDF to PNG/TIF

gswin32c.exe -dNOPAUSE -dBATCH -r300 -sDEVICE=pnggray -sOutputFile="test.png" "TestFile.PDF"
gswin32c.exe -dNOPAUSE -dBATCH -r300 -sDEVICE=pnggray -sOutputFile="c:\test.png" "c:\internet\Eudora\attach\12-30-2014 6-57 PM.pdf"
copy "c:\internet\Eudora\attach\12-30-2014 6-57 PM.pdf" .\
gswin32c.exe -dNOPAUSE -dBATCH -r300 -sDEVICE=pnggray -sOutputFile="test.png" "test.pdf"


the map file cidfmap was not found

gswin32c.exe -s OutputFile="test.png" "test.pdf"
gswin32c.exe -q -dNOPAUSE -sDEVICE=pngalpha -r300 -dEPSCrop -sOutputFile=test2.png test.pdf
gswin32c.exe -q -sOutputFile="test3.png" "test3.pdf"
gswin32c.exe -dNOPAUSE -dBATCH -r300 -sDEVICE=pnggray -sOutputFile="test.png" "TestFile.PDF"
gswin32c.exe -dNOPAUSE -dBATCH -sDEVICE=pnggray -sOutputFile="test.png" "test3.pdf"
gs -dSAFER -dBATCH document.pdf
gswin32c.exe -dSAFER -dBATCH "C:\Program Files\GPLGS\test3.pdf"

gswin32c.exe error occured while reading xref table

gs test.pdf
GPL Ghostscript 9.06 (2012-08-08)
Copyright (C) 2012 Artifex Software, Inc. All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
**** Error reading a content stream. The page may be incomplete.
**** Warning: An error occurred while reading an XREF table.
**** The file has been damaged. This may have been caused
**** by a problem while converting or transfering the file.
**** Ghostscript will attempt to recover the data.

A valid XREF table should be exactly 20 bytes long.

  • 10 digits for the byte offset
  • 1 space between the byte offset and the generation number
  • 5 digits for the generation number
  • 1 space as delimiter between the generation number and the in-use/free flag
  • 1 byte for the in-use/free flag

pdf won't convert using ghostscript unless i've saved it in acrobat using 'Optimized PDF'

some times ghostscript fails in opening files due to XREF table corruption

try to repair problematic pdf with

pdftk

   http://www.pdflabs.com/docs/install-pdftk/

pdftk file.pdf output fixed.pdf