Ghostscript is an interpreter for the PostScript language. A PostScript interpreter usually takes as input a set of graphics commands. The output is usually a page bitmap which is then sent to an output device such as a printer or display. PostScript is embedded in many printers.
Ghostscript has several main uses:
An example of a very simple PostScript file is:
%! /Helvetica findfont 72 scalefont setfont 72 72 moveto (Hello, world!) show showpageThe first line is a PostScript comment. It is ignored by the PostScript interpreter, but enables other programs to recognise that the file contains PostScript commands. The second line says to find the Helvetica font, scale it to 72 points high (1 inch) and then set it as the current font. The third line moves the current point to 1 inch in from the left and bottom edges of the page. The fourth line draws the text into the page bitmap at the current point. The final line causes the page bitmap to be output to paper or the display.
The information below assumes the use of GNU Ghostscript 6.51.
Other versions of Ghostscript are similar.
The Ghostscript program is typically found in
/usr/local/bin/gs
Ghostscript needs some initialization files in
/usr/local/lib/ghostscript/6.51
and some fonts in
/usr/local/lib/ghostscript/fonts.
The documenation files are in
/usr/local/lib/ghostscript/6.51/doc
and some example PostScript files are in
/usr/local/lib/ghostscript/6.51/examples.
gsIf Ghostscript has not been correclty installed, you will need to specify the full path, for example:
/usr/local/bin/gs -I/usr/local/lib/ghostscript/6.51:/usr/local/lib/ghostscript/fontsThe -I option tells Ghostscript to look for its configuration files and fonts in the two directories listed. After Ghostscript starts it will display
GNU Ghostscript 6.51 (2001-06-06) Copyright (C) 2001 artofcode LLC, Benicia, CA. All rights reserved. This software comes with NO WARRANTY: see the file COPYING for details. GS>An X11 image window will appear. Ghostscript is now waiting for you to tell it what to do. Typing (example.ps) run will produce
GS>(example.ps) run Loading NimbusSanL-Regu font from /usr/local/lib/ghostscript/fonts\n019003l.pfb... 1669824 366951 1300076 11892 0 done. >>showpage, press <return> to continue<<The text "Hello, world!" will appear near the bottom of the X11 image window. When you have finished viewing the image window, switch to the text window and press the <return> key. You will be returned to the GS> prompt. Type quit to close Ghostscript.
GS>quitIf the file is not in the current directory, then you will need to give a full path. For example, (/user/john/example.ps) run.
So now you know how to display a PostScript file. The same instructions apply for .pdf files as well. Some example PostScript files that come with Ghostscript are colorcir.ps, chess.ps and tiger.ps. These should be in the examples/ directory under the ghostscript tree.
gs -sDEVICE=djet500The output will be sent to a scratch file. Ghostscript will come up with the GS> prompt again, we give it a file name, and after processing each page it will pause. This is probably undesirable. A better way to start Ghostscript is:
gs -sDEVICE=djet500 -dNOPAUSE example.ps -c quitThis tells Ghostscript not to pause after each showpage, to interpret the file example.ps and afterwards to exit. This is much more useful.
To get a list of available printer devices, start Ghostscript for displaying, then type:
GS>devicenames ==The destination for the printed output can be specified on the command line. To output to the file out.prn, add -sOutputFile="out.prn" somewhere before the name of the PostScript file. To pipe the output to the lpr program, use -sOutputFile="\|lpr queuename"
If you are like me, you get sick of typing the long commands above. A program called gv and several derivatives exist for X11 on Unix or VMS. This allows you to display page 20 without having to display pages 1, 2, 3, 4, ... 20. You can also print selected pages.
You may also find useful the ggv application distributed with the GNOME desktop environment.
This page was written by Russell Lang and Ralph Giles.
Return to GNU's home page.
Please send FSF & GNU inquiries & questions to [email protected]. There are also other ways to contact the FSF.
Please send comments on these web pages to [email protected], send other questions to [email protected].
Copyright (C) 1997, 1998, 2001, 2005 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.
Updated: $Date: 2005/05/10 13:08:55 $ $Author: Arabidopsis $