Using GhostScript for Microsoft Windows

From Free Knowledge Base- The DUCK Project: information for everyone
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.

You can rename the windows executable, such as gswin32c.exe, to gs.exe and copy it to the c:\windows directory so that you can execute the "gs" command from the command shell interpreter giving it more of a *nix feel.

Usage Examples

Put multiple pdf files to one combined output

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

Rendering Postscript to a raster image (ppmraw)

gswin32c.exe -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

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

Convert a Color PDF to greyscale:

gswin32c.exe -dSAFER -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -sOutputFile=output.pdf input.pdf

Convert a PDF to JPG

gswin32c.exe -q -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sDEVICE=jpeg -r<OUTPUT RESOLUTION> -sOutputFile=<OUTPUT>.jpg <INPUT>.pdf

Convert a PDF to PNG

gswin32c.exe -q -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -sDEVICE=pdfwrite -r<OUTPUT RESOLUTION> -dPDFSETTINGS=/prepress -sOutputFile=<OUTPUT>.png <INPUT>.pdf

Troubleshooting

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