Ghostscript gs(1) is a postscript and pdf engine that can be used for a bunch of these, including rendering postscript files. On most linux systems, the Ghostscript interpretor is started with the gs(1) command. Arguments, including an input filename, output device and etc are all optional as they can be specfied within the interpretor interface itself. The Ghostscript prompt GS> indicates that the interpretor is ready to receive postscript commands. Typing quit will exit the interpretor.
1. Basics On most linux systems, the Ghostscript interpretor is started with the gs(1) command. Arguments, including an input filename, output device and etc. are all optional as they can be specfied within the interpretor interface itself. The Ghostscript prompt GS> indicates that the interpretor is ready to receive postscript commands. Typing quit will exit the interpretor.
2. Viewing a postscript file (X display device)
The ghostscript command can be used to view the contents of a postscript file simply by running gs(1) with the name of the postscript file as an argument.
However, if ghostscript is not given an output device, then it will choose the first available one that it finds and direct all output to that device. This may result in your postscript file not showing up on your X terminal as expected. This can be resolved by specifying the device (either on the command line with DEVICE= or within ghostscript itself, see point #3 for this). Typically the "x11" device is what's needed for rendering postscript to a display device. Refer to point #4 for more info on output devices.
bash % gs -sDEVICE=x11 some.ps
The above render page 1 of "some.ps" on the x11 device. To move to the next page either type "nextpage" or press enter at the "GS>" prompt.
Note that the desired output device must be selected before the postscript file is loaded, otherwise the preceeding (or default) device is used (this is also clearly applies to using commands within ghostscript)
3. Postscript commands
Ghostscript is a postscript interpretor and as such you can issue postscript commands at the GS> prompt. The following sequence of commands sets the device to "x11" and runs the postscript file "some.ps"
bash % gs
GS> GNU Ghostscript 7.07 (2003-05-17) GS> (x11) selectdevice GS> (some.ps) run GS) quit
4. Report known devices
Ghostscript will report the output devices it knows about as part of the help (-h) option. The output below is edited to reduce size:
bash % gs -h
GNU Ghostscript 7.07 (2003-05-17) Copyright (C) 2003 artofcode LLC, Benicia, CA. All rights reserved. Usage: gs [switches] [file1.ps file2.ps ...] Most frequently used switches: (you can use # in place of =) -sDEVICE=<devname> select device | -dBATCH exit after last file
Input formats: PostScript PostScriptLevel1 PostScriptLevel2 PDF Default output device: display Available devices: AP21xx DJ630 DJ6xx DJ6xxP DJ8xx DJ9xx DJ9xxVIP alc1900 alc2000 alc4000 bitcmyk bitrgb bj10e bj10v bj10vh bj200 bjc600 bjc800 bjc880j bjccmyk Search path: . : /usr/share/ghostscript/7.07/lib : /usr/share/ghostscript/7.07/vflib : For more information, see /usr/share/doc/ghostscript-7.07/Use.htm. Report bugs to bug-gs@ghostscript.com, using the form in Bug-form.htm.
5. Directing output to the printer
It's possible to use Ghostscripts "OutputFile" command to send the rendering to a printer. This is done by setting the output file to a piped command (note the pipe needs to be quoted to stop the shell from interpreting it straight away).
bash % gs -sOutputFile=\|lpr some.ps
6. Ghostscript doco
The installed Ghostscript (for linux) has documentation in /usr/share/doc as well as the man pages. There are examples as well. These absolute pathnames refer to version 7.07 of Ghostscript as installed for FC3.
/usr/share/ghostscript/7.07 Lib and examples /usr/share/doc/ghostscript-7.07 Doco directory: /usr/man/man1/gs*.1 Man pages. E.g., gs, gslp and etc.
7. Paging
Ghostscript paging is pretty obscure. It appears that phostscript files get "executed" (i.e., with commands like "(a.ps) run", which is implied with a filename is provided on the command line.
Whislt it's possible to start at an arbitrary page of a document, it doesn't appear possible to move back and forward through pages of a running document or if it is, then it's pretty weird and baroque.
By default, page prompts occur at the end of each page of a running document. Ghostscript (actually EPS) requires a bounding box to define the permimeter of the rendering area of the postscript being displayed and this is used this to determine where the end of a page is and Ghostscript puts a prompt and pauses for user interaction.
Pressing enter continues from the pause. Both the pause and the prompt (which is "showpage press return") can be disabled. Indeed Ghostscript can be directed to read it's prompt input from /dev/tty instead of stdin.
Some simple switches relating to pagination and prompting (lifted from GS 7.07 doco):
-dNOPAGEPROMPT Disables the prompt, but not the pause.
-dNOPAUSE Disables both the prompt and pause. This should be
used (along with -dBATCH) when producing output on
a printer or to a file.
-dNOPROMPT Disables the printed prompt by Ghostscript when it
expects interactive input, as well as the end-of-page
prompt (-dNOPAGEPROMPT); This allows piping input
directly into Ghostscript. Note, gs still pauses
though.
-dQUIET Suppresses information comments on standard output.
Required when redirecting device output to standard
output.
-dSHORTERRORS Makes certain error and information messages more
Adobe-compatible.
-sstdout=filename Redirect PostScript %stdout to a file or stderr.
Avoids it being mixed with device stdout. To redirect
stdout to stderr use -sstdout=%stderr. To cancel
redirection of stdout use -sstdout=%stdout or -sstdout=-.
-dTTYPAUSE Read a character from /dev/tty at the end of each page.
May be useful if input is coming from a pipe. Note that
-dTTYPAUSE overrides -dNOPAUSE.