Reading a PDF file for testing in GhostScript?

This question is related to this one - Toolkit / tool for PDF checking?

I've installed "ghostscript" on my Windows system and it gives me a prompt to type in. I'm not sure what I should do next in order to read in my existing PDF files that I want to test (to see if they were formed properly).


Solution 1:

If you use Ghostscript on Windows, you'll have two executables:

  1. gswin32c.exe
  2. gswin32.exe

The first one is to be run from inside a 'DOS box' (i.e. cmd.exe window) -- either interactively or not. It prints all stderr/stdout messages into the cmd.exe window and also expects any input commands to be typed in there.

The second one opens a separate Window for "interactivity': prints stderr/stdout to separate window, and expects commands there.

To avoid the 'prompt to type in', you have to use the right commandline parameters when you call either one of the commands. For example:

gswin32c.exe -dBATCH -dNOPAUSE

-dNOPAUSE processes all pages of the input file (instead of pausing after each one). -dBATCH avoids the return to the gs> prompt after the last page.

A complete command for Ghostscript to test your PDF would be (inside a DOS box) to run

gswin32c -o nul -sDEVICE=nullpage c:/path/to/input.pdf

(the -o parameter implicitly uses -dBATCH -dNOPAUSE.) -sDEVICE=nullpage doesn't do any conversion and doesn't write an output file. But it makes Ghostscript to run all the rendering commands of the input PDF. Should the input be invalid, Ghostscript will tell you with its stdout/stderr messages.

Solution 2:

If you want to look inside the PDF you can use various tools to see the object structure. I wrote blog articles on using CanOpener (http://www.jpedal.org/PDFblog/?p=627), PDFedit (http://www.jpedal.org/PDFblog/?p=452) and Acrobat (http://www.jpedal.org/PDFblog/?p=283).