This chapter covers installation and use of Ghostscript, a PostScript interpreter. Almost everything related to Linux is in PostScript. If you have a PostScript printer, you simply send the file to the printer for a hardcopy.
Ghostscript is actually a set of programs. Collectively, these programs provide two important features:
PostScript is a trademark of Adobe Systems, Incorporated.
Ghostscript has been ported to several platforms from PCs, OS/2, Apple Macintoshes, Ataris, to various flavors of UNIX, for example, Sun workstations, IBM AIX machines, and so on. Since Ghostscript is written in C, chances are that it will be portable
to your platform. If you support X11, you will probably be able to run Ghostscript.
Several executable files come with Ghostscript. Some of the executables are also used by other packages under Linux. For example, HylaFAX (Chapter 59, "Using FlexFAX, sendfax, and mgetty") uses the main Ghostscript
program, gs. In short, if you use Linux, you will find a need for Ghostscript.
The primary contact for getting information about Ghostscript is:
P.O. Box 60264
Palo Alto, CA 94306
voice (415) 322-0103
FAX (415) 322-1734
In fact, the Ghostscript package that you get with Linux is from Aladdin Enterprises. The information about Ghostscript is best summarized in its README file:
"L. Peter Deutsch, president of Aladdin Enterprises, was the original creator, and is the primary developer and maintainer, of Ghostscript. Aladdin Enterprises owns the Copy on Ghostscript; Ghostscript is distributed with the GNU General
Public License, and is also available for commercial licensing."
To run Ghostscript, you need the executable program and some external initialization files:
/usr/lib/ghostscript/bdftops.ps /usr/lib/ghostscript/decrypt.ps /usr/lib/ghostscript/font2c.ps /usr/lib/ghostscript/gs_dbt_e.ps /usr/lib/ghostscript/gs_dps1.ps /usr/lib/ghostscript/gs_fonts.ps /usr/lib/ghostscript/gs_init.ps /usr/lib/ghostscript/gs_lev2.ps /usr/lib/ghostscript/gs_statd.ps /usr/lib/ghostscript/gs_sym_e.ps /usr/lib/ghostscript/gs_type0.ps /usr/lib/ghostscript/gslp.ps /usr/lib/ghostscript/impath.ps /usr/lib/ghostscript/landscap.ps /usr/lib/ghostscript/level1.ps /usr/lib/ghostscript/prfont.ps /usr/lib/ghostscript/ps2ascii.ps /usr/lib/ghostscript/ps2epsi.ps /usr/lib/ghostscript/ps2image.ps /usr/lib/ghostscript/pstoppm.ps /usr/lib/ghostscript/quit.ps /usr/lib/ghostscript/showpage.ps /usr/lib/ghostscript/type1ops.ps /usr/lib/ghostscript/wrfont.ps /usr/lib/ghostscript/uglyr.gsf /usr/lib/ghostscript/Fontmap
The Ghostscript file set includes a set of fonts (.gsf files). You should have them online as well.
Installing Ghostscript on a Linux system simply requires getting it from the CD-ROM or Internet. The name of the executable is gs.
You can build Ghostscript on your machine if you want to. The makefiles that come with the sources will install all the files and directories under your /usr/local directory.
The Ghostscript interpreter is the gs command in /usr/bin/gs. This is an interactive interpreter that also reads in files for its input. To invoke the gs interpreter, use the command
gs [filename1] ... [filenameN]
The interpreter will read in the files in sequence and interpret them. After doing this, it reads further input from the primary input stream (normally the keyboard). Each line (that is, characters up to a <return>) is interpreted separately. To
exit from the interpreter, type quit and press the Return key. The interpreter also exits gracefully if it encounters end-of-file. Typing the interrupt character (Ctrl-C), is also safe.
See Figure 25.1 for the input to the interpreter. (Your version number may be different than that shown in the figure.) The output is shown in a separate window as shown in Figure 25.2 (which shows the FlexFAX FAQ). The file in this example is the FAQ
for the HylaFAX program (see Chapter 59) and is called fax-112894.ps. You can get this file via Mosaic (see Chapter 56, "Using Mosaic and Netscape") from www.vix.com from the HylaFAX directory.
Figure 25.1. The gs interpreter.
Figure 25.2. The output from gs interpreter.
The gs interpreter recognizes several arguments. We will cover most of the important ones in this chapter. However, you can get help from gs too. Either the -h or -? option tells gs to print out a help screen. The help screen also lists all available
devices for gs on your system.
Ghostscript may be built with multiple output devices. Ghostscript normally opens the first one and directs output to it. To use device Laserjet as the initial output device, include the following argument in the command line:
Command line arguments to gs can appear anywhere on the command line. Once specified, these arguments apply to all subsequent files listed in the command line. These arguments will not apply to any files specified before the argument. So if you have important arguments like sDEVICE, specify these arguments before you specify the PostScript file.
PostScript files are usually specified with the .ps extension.
For example, for printer output in a normal configuration that includes a Laserjet printer driver, you might use the shell command
gs -sDEVICE=laserjet showme.ps
Alternatively, in the interpreter you can type
(laserjet) selectdevice (showme.ps) run
All output then goes to the printer instead of the display until changed. You can switch devices at any time by using the selectdevice function, for example,
(vga) selectdevice # for VGA screen
(nec) selectdevice #for NEC printer
As yet a third alternative, you can define an environment variable GS_DEVICE as the desired default device name. The order of precedence for these alternatives, highest to lowest, is this:
selectdevice (command line) GS_DEVICE (first device in build list)
To select the density on a printer, use the command
gs -sDEVICE=<device> -r<xres>x<yres>
For example, on a nine-pin, Epson-compatible printer, you can get the lowest-density (fastest) mode with the command
gs -sDEVICE=epson -r60x72
For the highest-density mode with Epson printers, use
gs -sDEVICE=epson -r240x72.
If you select a printer as the output device, Ghostscript also enables you to control where the device sends its output.
For compatibility with older versions of Ghostscript, -sOUTPUTFILE= also works.
The %d is a printf format specification. You can use other formats like %02d. Each file will receive one page of output. Alternatively, to send the output to a single file bigfile.xyz, with all the pages concatenated, use the command line argument:
On UNIX-like systems, you can send the output directly to a pipe. For example, to pipe the output to the command lpr (which, on many UNIX systems, is the command that spools output for a printer), use the switch
Don't forget to escape the pipe symbol (|). You can also send output to stdout for piping with the dash as the output file. That is, use the option -sOutputFile=-. In this case you must also use the -q switch to prevent Ghostscript from writing messages
Ghostscript is normally configured to expect U.S. letter size paper. To select a different paper size as the default, use the argument -sPAPERSIZE=known_paper_size. (You can create your own paper sizes with the devs.mak file.) Generally, you have a
large selection available. The entire list can be found in the file
Print this file out if you can, to keep it handy. Some examples of setting the paper size are
-sPAPERSIZE=a4 -sPAPERSIZE=legal -sPAPERSIZE=11x17 -sPAPERSIZE=ledger
A PostScript file may explicitly specify the paper size. In this case, the file's specification will override any command line argument specification.
Ghostscript uses these environment variables: GS_LIB, GS_LIB_DEFAULT, and GS_FONTPATH.
When looking for the initialization files (gs_*.ps), the files related to fonts, or the file for the run operator, Ghostscript first tries opening the file with the name as given (that is, using the current working directory if none is specified). If
this fails, and the filename doesn't specify an explicit directory or drive (that is, doesn't begin with / on UNIX), Ghostscript will try directories in the following order:
Ghostscript will create temporary files by using the TEMP environment variable as the location of the /tmp directory. These files are named gs_XXXXX, where XXXXX is replaced by a number or a string of jumbled characters. Ghostscript doesn't do a very good job of deleting temporary files when it exits. If you see your /tmp space being used by these files you may have to delete them using the rm /tmp/gs_* command.
Ghostscript looks for the resources under the program name ghostscript and class name Ghostscript in the .Xdefaults file. To set a resource, put the resource in .Xdefaults in the following form:
Then load the defaults into the X server:
% xrdb -merge ~/.Xdefaults
Table 25.1 lists the options available to you.
Here are a few points on these resources:
To use native X11 fonts, Ghostscript must map PostScript font names to the XLFD font names. The regularFonts, symbolFonts, and dingbatFonts resources give the name mapping for different encodings. The XLFD font name in the mapping must contain seven
dashes. The X driver adds the additional size and encoding fields to bring the total number of dashes in the font name to 14. The default font mappings are found in the FontMap file in /usr/lib/ghostscript or check the man pages.
Ghostscript takes a lot of command-line arguments. Generally you would want to put these in a shell script file instead of having to type them in all the time. Some of the most often used arguments are listed here. For a comprehensive list check out the
documents in /usr/lib/ghostscript/doc. Let's look at the most commonly used arguments:
The differences between -d and -s are these:
-dfoo=hello is equivalent to /foo hello def
-sfoo=hello is equivalent to /foo (hello) def
Ghostview is used to display encoded PostScript files. Ghostview is free. It was written and ed by Tim Theisen. The ghostview command shows PostScript documents using Ghostscript.
Use the command line below to view a text file.
$ ghostview [filename]
The ghostview program will create an X window, open the file, and display it. If the filename is '-', ghostview will read from stdin. The ghostview program provides an X11 user interface for the Ghostscript interpreter. ghostview and Ghostscript
function as two cooperating programs. ghostview creates the viewing window and Ghostscript draws in it.
Please use Ghostview to view files, especially those that require typesetting before sending them to the printer. You can save a lot of trees this way and get a quicker response about what to expect on the output. There are many programmers who still print out files to see what the output would look like instead of previewing on the screen.
In fact you may not even have to print out a document if you intend to send it to a remote site. If you have to FAX it, use HylaFAX (Chapter 59) with your FAX/modem to send it directly. If you have to e-mail it, uuencode it and then send it out.
Ghostview has a bewildering number of options. You do not have to use any of these options at all. Most of the options are there to override any Xresources that you set in .Xdefaults. Let's look at the main window, which consists of a main viewer and
control menus (of HylaFAX). (See Figure 25.3.)
The main viewport is on the right side of the main window. If the page is larger than the viewport, there will be scroll bars along the bottom and right edges of the viewport. To the left of the viewport is the table of contents. If the PostScript file
has document structuring convention (DSC) comments, the table of contents will display the page labels (these are usually page numbers). To the left of the table of contents is a menu box. Each push button brings up a pop-up menu.
Above the menu box and table of contents there are three optional labels that contain the title, date, and locator.
The title label contains the document title found in the DSC comments. If no title can be found, the filename is used in its place. The date label contains the document date found in the DSC comments. If no date can be found, the last modified date of
the file is used in its place. Since the title and date labels may be clipped by the main viewport, the date and title labels are pushbuttons that bring up a pop-up window with the title or date. These pop-up windows also show the document icon when the
displayed string comes from the DSC comments.
The locator shows the location of the cursor in the viewport. The location is expressed in the default user coordinate system. The locator is useful for measuring bounding boxes. Within the main viewport, the mouse cursor is a "target" when
Ghostscript is doing work. The cursor is a crosshair when Ghostscript is idle.
When moving to another page in a document, it is generally best to wait for Ghostscript to become idle. Ghostscript does not handle a series of mouse clicks very well while it's working and can hang. You then have to use the kill command to get rid of it, and start over.
Ghostview will always check to see if the file has been modified just before it displays a page or when the application is de-iconified. If the file has changed, it will re-open the file. This causes a bit of an overhead, but is helpful when you are
trying to edit a file from another program and need to see your progress.
Clicking anywhere within the viewport will pop up a zoom window. The window is centered on the location that was clicked. Clicking with the left mouse button pops up a low-resolution zoom window. Clicking with the center mouse button pops up a
medium-resolution zoom window. Clicking with the right mouse button pops up a high-resolution zoom window.
In the table of contents, the left mouse button selects text and the right mouse button extends selections. However, clicking on a page label with the center mouse button will display that page. The page being displayed is marked with a greater than
symbol (>) in the right margin of the table of contents.
There are five buttons in the menu box. These are listed below:
Some of the pop-up menu commands can be executed with the keyboard. The pop-up menu has to be active (in other words, selected by the user for input) for the action to have effect. Some of the bindings are listed in Table 25.2.
|Q||The Quit menu button|
|O||The Open... menu button on the File menu|
|R||The Reopen... menu button on the File menu|
|S||The Save marked pages on the File menu|
|P||The Print marked pages on the File menu|
|Shift-P||The Print all pages on the File menu|
|BackSpace, B space||The Previous menu button on the Page menu|
|Return, F period||The Next menu button on the Page menu|
|Ctrl-L||The Redisplay menu button on the Page menu|
|M||The Mark menu button on the Page menu|
|[lb]||The Unmark menu button on the Page menu|
|0-5||Selecting the 0 through 5 menu button on the Magstep menu|
|+||Increases the Magstep by 1|
|-||Decreases the Magstep by 1|
You can set the following resources for Ghostview. Only the most frequently used resources are listed. Please check the lengthy man page for Ghostview script for its long list of resources.
Remember that almost all of these resources can be set with the command line argument. For example, the -title argument is equivalent to setting Ghostview.showTitle resource to True, whereas the -notitle argument is equivalent to setting the Title
resource to False. Similarly, you can turn the date on or off with the -date and -nodate arguments, respectively.
The versions of Ghostscript come with a set of default fonts that you can use with any program capable of reading PostScript Type 1 and Type 3 fonts. If you have created your own Type 1 or Type 3 fonts, or have purchased some fonts from another source,
you can use these with Ghostscript. Place your fonts in the lib/ghostscript/fonts directory. Then edit the lib/ghostscript/FontMap file to add a line telling Ghostscript where to find the font. For example,
Aladdin Enterprises, the inventors of Ghostscript, do not have the resources to respond to questions from general users of Ghostscript. There are plenty of other places where you can get very detailed information about Ghostscript.
If you have access to newsgroups, post your questions to gnu.ghostscript.bug. There are literally hundreds of Ghostscript users all over the world who are very willing to help you. After all, we all started learning on our own. Using this newsgroup is
perhaps the quickest way to get more information on gs.
If you have access to Internet mail, but not news, send e-mail to firstname.lastname@example.org. If you are having trouble with a specific device driver, look in the file devs.mak
and see if it is a user-maintained driver. If so, please contact directly the person listed.
There are several files in the /usr/lib/ghostscript/doc directory which can provide more information. Some of these files are:
There are several files in the /usr/lib/ghostscript/doc directory which can provide more information. Some of these files are:
This chapter scratched the surface of a very important PostScript processing program called Ghostscript. The executable file for Ghostscript is called gs. You can use gs to decode PostScript files for displaying or printing hard copies.
Ghostscript is also used by other programs as a filter for working with PostScript printers that cannot switch from PostScript to text and back just by looking at a document. In this case, the gs command is used to convert text to PostScript with an
output filter for lp before sending the text to a PostScript printer. As another example, HylaFAX uses gs as its primary PostScript output filter program.
Ghostview is an X Windowbased program that provides a canvas for ghostscript to write its output to. Ghostview enables you to scroll through a multi-page document, zoom in and out, and save marked pages. The ability to view EPSI or PostScript via Ghostscript saves time and paper when typesetting documents.