Ghostscript 5
What is Ghostscript?
                                                                   Installing Ghostscript
                                                                   Building Ghostscript from C Source
                                                                   Ghostscript Primer
                                                                   Ghostscript Reference
                                                                   More Ghostscript Applications
Ghostscript User Manual
© Thomas Merz 1996-97 (tm@muc.de)
This manual is adapted from appendix
B of the following book: »PostScript
and Acrobat/PDF. Applications,
Troubleshooting, and Cross-Platform
Publishing« by Thomas Merz,
Springer Verlag Berlin Heidelberg
New York 1997, ISBN 3-540-60854-0,
420 pages plus CD-ROM. Book and
manual are also available in German
(Thomas Merz Verlag München, ISBN
3-9804943-0-6).
The Ghostscript manual may be freely copied and redistributed
in printed or digital form if no payment is involved. Commercial
reproduction is prohibited. However, the author agrees to any
redistribution along with the Ghostscript software, provided the
distributor complies with the applicable Ghostscript license
terms.
The Ghostscript manual is available from
http://www.muc.de/~tm.
                                                                                1 What is Ghostscript?
                                                                                 L. Peter Deutsch, founder of Aladdin Enterprises, Menlo Park,
                                                                                 California, wrote the PostScript Level 2 and PDF interpreter
                                                                                 Ghostscript in the C programming language. The program runs
                                                                                 on most operating systems, including MS-DOS, Windows 3.x,
                                                                                 Windows 95, Windows NT, OS/2, Macintosh, Unix, and VAX/
                                                                                 VMS, and has been available free of charge ever since its intro-
                                                                                 duction in 1988. With the help of many users and programmers
                                                                                 on the Internet Ghostscript has become a high-quality and ver-
                                                                                 satile PostScript interpreter. Peter Deutsch also distributes a
                                                                                 commercial version with customer-specific enhancements and
                                                                                 support. Ghostscript’s capabilities include:
                                                                                 Screen output. Ghostscript displays PostScript and PDF
                                                                                 data on the screen. This is useful to examine PostScript graphics
                                                                                 or for saving a few trees if you want to browse some product
                                                                                 documentation which is available in PostScript format only.
                                                                                 Ghostscript checks PostScript files before you transfer them
                                                                                 (e.g., to a service bureau): Are all the necessary fonts there? Are
                                                                                 the graphics okay? Do the files contain all pages?
                                                                                     Ghostscript also helps with PostScript trouble-shooting: A
                                                                                 faulty page can be rendered on screen revealing which graphics
                                                                                 element yields an error message. Ghostscript provides the usual
Ghostscript User Manual                                                          PostScript error messages. A separate frontend to the interpret-
© Thomas Merz 1996-97                                                            er, called GSview (for Windows and OS/2) or Ghostview (for
                                                                                 the X Window System), simplifies the handling of PostScript
Notes on the page layout. The design of the Ghostscript manual was               files with a user-friendly GUI interface: with these frontends the
chosen to meet several objectives:
 ➤ It uses fonts from the PostScript core font set in order to reduce file       user can access random pages in the document. Without them,
    size. This also avoids font embedding issues since the original book
    layout uses fonts from the commercial Thesis family.
                                                                                 Ghostscript displays the pages one after another, from the be-
 ➤ Pages can be printed on both letter and A4 format paper. The double-          ginning to the end of the file.
    page design also makes it easy to read the manual on screen.
 ➤ A two-page spread was slightly reduced and printed on one sheet of
    paper in order to economically make use of paper and screen estate.          Printer output. Another important task of a PostScript RIP is
                                                                                 to render PostScript data for output on a graphics-capable
Production notes. I created a PostScript file from the FrameMaker file           printer. The Ghostscript distribution contains a wealth of driv-
via the PostScript printer driver. The resulting PostScript file was convert-
ed to PDF using Acrobat Distiller 3.0. Bookmarks and article threads were        ers for a wide range of printer models, from the more popular
automatically generated by FrameMaker. Additionally, I inserted several
pdfmark instructions in the document manually, e.g. to populate the docu-        to the more esoteric. A list of all drivers is found in section 3.3,
ment info fields and to set the open mode of the PDF file.                       »Configuration Options and Drivers«. These drivers are an inte-
                                                                                 gral part of Ghostscript and are not related to Macintosh or
This is version 1.3 of the manual. It covers Ghostscript 5.01 and GSview 2.2.
                                                                                 Windows system drivers.
 Ghostscript User Manual                                                                                                Chapter 1: What is Ghostscript?   2
Ghostscript can even help optimize the output of a PostScript-         Public License (AGFPL). Under the terms of the AGFPL, no
capable printer: if the computer’s CPU is significantly faster         payment is required for private and commercial use of the pro-
than the printer’s, Ghostscript can in many cases speed up Post-       gram. The sale of Ghostscript is explicitly prohibited, however.
Script output. PostScript printers with too little RAM some-           Exempted from these conditions are BBSs, or servers for which
times cause trouble. Ghostscript can remedy this by making use         users pay access fees independent of the downloaded software,
of your computer’s main memory (and a swap file or swap par-           and CD-ROMs whose contents may be reproduced and distrib-
tition). Ghostscript has proven to be a robust and reliable Post-      uted without any payment involved. Anyone interested in com-
Script RIP that is superior to many commercial PostScript              mercially licensing Ghostscript should contact Aladdin Enter-
clones.                                                                prises or one of its distribution partners. The complete text of
                                                                       the AGFPL is found in the file named PUBLIC which is part of
PDF on every platform. Beginning with version 3.33, Ghost-             the Ghostscript distribution fileset.
script also contains an interpreter for the Portable Document For-
mat (PDF), the foundation of Adobe Acrobat. Large parts of
Ghostscript’s PDF interpreter are written in PostScript. It dis-
plays and prints PDF files and even converts them back to Post-
Script. However, Ghostscript only interprets layout-related in-
formation and currently ignores hypertext links or annotations.
   Starting with Ghostscript 4.0, the program is also capable of
converting PostScript files to PDF, i.e., it offers Distiller func-
tionality. Though this feature, called the pdfwrite device, still
has some shortcomings, it is certainly an important milestone
since Ghostscript is the first free Acrobat Distiller substitute.
Utilities and converters. A complete PostScript interpreter
together with suitable drivers and utilities makes it possible to
carry out many of the operations covered in this book. These
include displaying graphics files in the formats GIF, JPEG, or
PBM; extracting textual data from PostScript or PDF files; ras-
terizing PostScript to raster graphics formats such as TIFF,
PBM, PNG; converting EPS graphics to the editable Illustrator
format, and many other useful features.
License conditions for the end-user. Although Ghost-
script is available free of charge, it is subject to certain license
conditions. These are always contained in the Ghostscript pro-
gram package. Until 1994, Ghostscript was subject to the GNU
Public License (GPL). Under the terms of this license, the origi-
nator retains the copyright for his work. The use and further
distribution of the program, however, are not restricted signifi-
cantly. Starting with version 3.0 in 1994, Peter Deutsch replaced
the GPL with the more restrictive Aladdin Ghostscript Free
 Ghostscript User Manual                                                                                   Chapter 1: What is Ghostscript?   3
        2 Installing Ghostscript                                                               Ghostscript by supplying a handy interface to the interpreter.
                                                                                               With the GSview setup program you can install both Ghost-
     2.1 Using GSview for Windows and OS/2                                                     script and GSview comfortably. After uncompressing the zip
                                                                                               file of GSview, launch the program setup.exe (for Windows) or
             Requirements and versions. The Ghostscript and GSview
             installation (including fonts) uses 5.5 MB hard disk space. There                 os2setup.exe (for OS/2). The file readme.txt lists the required ZIP
             are several flavors of Ghostscript for PC systems (note that sup-                 files. After asking for the version of Ghostscript you wish to
             port for 16-bit MS-DOS and WIndows versions has been                              use, the setup program asks for the name of the directory to
             dropped in Ghostscript 5.0):                                                      which the software is to be installed, and decompresses the ZIP
                                                                                               archives. Then it creates a program group (Windows 3.x) or a
             System              File name        Notes                                        start menu entry (Windows 95, NT 4.0).
             MS-DOS,             gs386.exe plus   Version with DOS extender; very fast.            When GSview is first run, it asks whether you want to create
             80386 and higher    dos4gw.exe                                                    a file association between GSview and files with the extension
             Windows 3.x with    gswin32.exe plus 32-bit version with enhancements for         .ps, .eps, and .pdf. This means that double-clicking a file of the
             Win32s;             gsdll32.dll;     Windows 95 and NT; it consists of a DLL      respective type launches GSview automatically. You may al-
             Windows 95 and NT   gs16spl.exe      and a (small) EXE program.
                                                                                               ways want to have the .ps and .eps associations created; how-
             OS/2                gsos2.exe plus   Uses gspmdrv.exe as display driver for the
                                 gsdll2.dll       presentation manager.                        ever, create the .pdf association only if you don’t use Acrobat
                                                                                               Reader.
                                                                                                   If you moved the Ghostscript files to another directory you
             Setup program for Ghostscript and GSview. Under Win-                              have to choose “Options”, “Configure Ghostscript...” after
             dows and OS/2 the user frontend GSview facilitates using                          launching GSview to enter the path name of the Ghostscript
                                                                                               DLL, the include path, and possibly some Ghostscript options
                      Fig. 1.                                                                  (see figure 2).
GSview simplifies Ghost-                                                                       With “File”, “Open” you can open PostScript and PDF files. GS-
      script usage under
  Windows and OS/2. It                                                                         view then passes these files on to Ghostscript for rendering.
    also offers additional                                                                     Using the menu sequence “Media”, “Display Settings...” you
possibilities, e.g., dealing
           with EPS files.
                                                                                               can adjust the screen size: larger resolution values yield a larger
                                                                                               screen representation. Use a smaller resolution value if you
                                                                                               want to see the entire page at a time without scrollbars. With
                                                                                               the “Media” menu you can adjust the page size (media format).
                                                                                                                                                             Fig. 2.
                                                                                                                                                             Configuring
                                                                                                                                                             Ghostscript
                                                                                                                                                             path names in
                                                                                                                                                             GSview.
              Ghostscript User Manual                                                                                               Chapter 2: Installing Ghostscript   4
   Additional features of GSview. GSview offers many addi-                   Launching and testing Ghostscript. On MS-DOS, you
   tional Ghostscript functions which are described in several               start Ghostscript by typing the program name gs386. In Win-
   chapters of this book. This includes dealing with EPS files, ran-         dows it’s easier to double-click on Ghostscript’s icon in the file
   domly accessing the pages of DSC (Document Structuring Con-               manager or Explorer, or to create an icon in the program man-
   ventions) conforming PostScript files, following hypertext links          ager/start menu. The file tiger.ps (part of the Ghostscript distri-
   in PDF files, extracting selected pages to print parts of a docu-         bution) is perfectly suited to test your installation. Start Ghost-
   ment only, copying the bitmapped page contents to the clip-               script and type in the following command at Ghostscript’s
   board, or selecting printer drivers in a convenient manner.               prompt:
      GSview uses temporary files for printing and for extracting            GS>(tiger.ps) run
   text. These temporary files are normally created in the directory
                                                                             Ghostscript should now display the test file on screen. Having
   specified in the TEMP environment variable. A warning will be
                                                                             finished the page, Ghostscript asks you to
   given if the TEMP variable is not set. The TEMP variable must
   therefore point to a writable directory on disk if GSview is run          >>showpage, press <return> to continue<<
   from CD-ROM.                                                              If the file contains more than one page, Ghostscript renders the
                                                                             next page after the return key is pressed.
                                                                                 Caution: The installation is not yet complete! To complete
2.2 Installing Ghostscript without GSview
                                                                             the installation, font access for Ghostscript needs to be config-
   If you don’t use Windows, don’t need GSview, or can’t stand               ured. This is covered in section 2.5, »Font Configuration«. If you
   setup programs, you can install Ghostscript manually. All of              want Ghostscript to use the same command line options every
   the files contained in the archive gs5xxini.zip plus one of the ex-       time, you can use the environment variable GS_OPTIONS.
   ecutables listed in the table in section 2.1 are necessary for using      Ghostscript evaluates this variable before checking the “real”
   Ghostscript. The executables for Windows and OS/2 are con-                command line options. Especially with Windows 3.x this is
   tained in the compressed files gs5xxw32.zip and gs5xxos2.zip, re-         much more convenient than the rather clumsy call by way of
   spectively. Note that you can also use ghostscript-5.xxpc.tar.gz.         the program manager and “File”, “Run...”
   You will need the tar and gzip utilities to unpack this archive.
       To use the 32-bit version for Windows 3.x, you need the
   win32s system extension in addition to the Ghostscript files.          2.3 Installing Ghostscript on the Macintosh
   (Note: many software packages use win32s, so it may already               Requirements and versions. Currently, there are two Mac
   be installed on your system.)                                             ports of Ghostscript available. The first is called Mac GS Viewer
        The MS-DOS version of Ghostscript uses the environment               and is based on Ghostscript 3.33. A Mac version of GS 4.03 is
   variable GS_LIB to locate the initialization files if they cannot be      available as part of the CMacTeX package from
   found in the current directory or the standard directory c:\gs.
                                                                             http://www.math.tamu.edu/~tkiffe/cmactex.html
   It’s best to include the following statements in your autoexec.bat
   file (assuming you installed Ghostscript in d:\progs\gs):                 The following description applies to Mac GS Viewer. It’s avail-
                                                                             able in three versions, one for Macs with Motorola CPU 68020
   set GS_LIB=d:\progs\gs                                                    and higher, a native version for PowerPCs, and a version for
   set PATH=...other path entries...;d:\progs\gs
                                                                             Mac Classics with 68000 CPU (min. 3 MB available memory).
   Alternatively, the command line option -I can be used to tell             The installation needs approximately 6 MB disk space (includ-
   Ghostscript where to find its files:                                      ing fonts). Contrary to Windows and OS/2, there is no equiva-
   gs -Id:\progs\gs                                                          lent of GSview for the Mac. Fortunately, this deficiency is com-
    Ghostscript User Manual                                                                                        Chapter 2: Installing Ghostscript   5
                                                                                                                                            Fig. 4.
                                                                                                                                            In the “Devices” menu you
            Fig. 3.                                                                                                                         can choose a driver for Mac
  Mac GS Viewer                                                                                                                             GS Viewer.
 displays the tiger
test page. You can
  enter PostScript                                                                    loon help to learn more about Ghostscript. After one page has
 commands in the                                                                      been rendered on screen, the next page can be requested with
   console window
 and open files via                                                                   “Ghostscript”, “Next Page”. The program can be closed with
            “File”.                                                                   “Quit”. The sequence “Edit”, “Settings...” changes such internal
                                                                                      settings as page size or the scaling factor of the window.
              pensated for by several extensions in Mac GS Viewer and its             Device drivers and file output. By default, Ghostscript ren-
              user interface.                                                         ders into a Macintosh window. It can also create instructions for
                 To install Mac GS Viewer you need the program Stuffit Ex-            other devices or graphics file formats. You can copy the bit-
              pander. Decompress the archive macgs-v1.0-files.sit.hqx.                mapped contents of a window to the clipboard, or save it as a
              This places the contents of this archive in the Ghostscript folder.     PICT file with “File”, “Save As...”. In the “Devices” menu you
              Decompress one of the executable files                                  can choose the output file. Although the Ghostscript source dis-
              macgs-v1.0-ppc.sit.hqx                                                  tribution contains many dozens of drivers, the Macintosh ver-
              macgs-v1.0-68k.sit.hqx                                                  sion only contains the screen driver, a few printer drivers, and
              macgs-v1.0-classic.sit.hqx
                                                                                      drivers for the file formats PCX, PBM, and TIFF. This decision
              along with the Ghostscript fonts from the archive macgs-v1.0-           has been made in order to reduce storage requirements. Since it
              fonts.sit.hqx into the same folder. The archive macgs-v1.0-             is not possible to dynamically load drivers, you have to recom-
              src.sit.hqx is only needed for compiling an individual version          pile Ghostscript if you want to use additional drivers.
              of Ghostscript.
                                                                                      Font configuration on the Mac. Ghostscript uses Post-
              Launching and testing Ghostscript. Launch Ghostscript                   Script fonts in ASCII format. Since PostScript fonts on the Mac
              by double-clicking on the Mac GS Viewer icon. After initializa-         are usually stored in a compact resource format, Ghostscript
              tion, the console window (“Talk to Ghostscript”) will appear            cannot use them directly (this is planned for a future version).
              with the Ghostscript prompt                                             However, you can convert standard Mac PostScript fonts for
              GS>                                                                     use with Ghostscript with the unadobe utility. Execute the fol-
              Although you can type in PostScript commands in the console             lowing steps for each font you want to use:
              window, it’s much easier to use Mac-style menu commands.                 ➤ Start unadobe and open the font file. unadobe doesn’t change
              The sequence “File”, “Open” lets you open EPSF or TEXT files,              the font data, but instead converts the resource representa-
              e.g., the test file tiger.ps in the Ghostscript folder. Activate bal-      tion to a textual representation suitable for Ghostscript. Save
               Ghostscript User Manual                                                                                     Chapter 2: Installing Ghostscript    6
      the generated font file in the Ghostscript folder (using the
      old file name or a new one).
    ➤ Edit the file Fontmap in the Ghostscript folder with a text edi-
      tor (e.g., SimpleText). Append a line similar to the following
      at the end of the file:
         /TheSerifBold-Italic        (TheSerBol)           ;
      This line contains the PostScript name of the font and the
      name of the font file that you used in the first step. The line
      must be terminated with a semicolon. If you’re unsure about
      the exact PostScript name of the font, you can open the font
      file created by unadobe with a text editor and look for the en-
      try /FontName.
    ➤ Launch Ghostscript to test the font. You can either use a suit-
      able PostScript file or request the font manually in the con-                                                                              Fig. 5.
      sole window:                                                                                                                               With Ghostview for X11
                                                                                                                                                 you can easily control
         /TheSerifBold-Italic findfont                                                                                                           Ghostscript for screen and
                                                                                                                                                 printer output. The page
   Alternatively, you can install a fontmap file derived from an-                                                                                list allows quick access to
                                                                                                                                                 random pages of DSC
   other platform. For example, you can create the fontmap auto-                                                                                 compliant documents.
   matically on Windows (see section 2.5, »Font Configuration«)
   and install it in the Ghostscript folder together with the font
   files. It’s important not to change the font file names so make       URW++ contributed commercial-quality PostScript Type 1
   sure that they correspond to the fontmap entries. Naturally,          fonts for use with the Ghostscript package. These include look-
   you have to observe the font manufacturer’s license conditions        alikes for the 35 PostScript core fonts found in most laser print-
   if the installed fonts originate from another system.                 ers. The URW++ fonts are distributed under the Aladdin and
                                                                         the GNU license.
                                                                            Ghostscript accepts many flavors of font formats:
2.4 Installing Ghostscript on Unix
                                                                         Type 0               Composite fonts (large fonts composed of other fonts)
    Using Ghostscript on Unix systems generally requires compil-
                                                                         Type 1               commonly used PostScript outline fonts; ASCII (*.pfa) or bina-
   ing the C source first. This process is covered in section 3,
                                                                                              ry (*.pfb) files.
   »Building Ghostscript from C Source«.
                                                                         Type 2               Type 1 extension used in the Compressed Font Format (CFF)
      If you’re working with the X Window System, driving                                     and OpenType
   Ghostscript with the Ghostview frontend is a good idea.               Type 3               rarely used PostScript fonts (outline or bitmap)
                                                                         Multiple Master      Type 1 extension with one or more design axes (parameters)
                                                                         CID (character id)   Format used for large character sets, e.g. Chinese and Japanese
2.5 Font Configuration
                                                                         Type 42              TrueType font data wrapped in PostScript
   This section applies to all operating systems except the Macin-       TrueType             Native TrueType font file (*.ttf)
   tosh. Font configuration for the Mac differs from other systems
   and has been covered with the Mac installation already.
      For many years, the Ghostscript distribution contained only
   low quality public domain fonts. In 1996, the German company
    Ghostscript User Manual                                                                                             Chapter 2: Installing Ghostscript       7
It is necessary for Ghostscript to have access to the font file (in-   In order to let Ghostscript access the fonts in Display PostScript
stalling the font in the operating system, ATM, or Display Post-       systems, you have to include the appropriate path name in
Script is not enough).                                                 GS_LIB.
    If you install Ghostscript with GSview, the URW font set is
automatically installed. If you only want to use the PostScript        Dynamic font configuration. For large or frequently chang-
core font set, the font configuration is already finished.             ing font installations the second method is preferable. Ghost-
                                                                       script checks the GS_FONTPATH environment variable to de-
Static font configuration. There are two choices for the font          termine the available font files and scans these files to find out
configuration. If the installed font base rarely changes, put one      the names of the fonts they contain. Similar to GS_LIB above,
or more font directories in the environment variable GS_LIB. A         this variable contains one or more directory names. Since
typical hard disk installation on MS-DOS or Windows uses the           Ghostscript automatically recognizes fonts, this method is
following:                                                             much more flexible. However, since Ghostscript checks all font
set GS_LIB=C:\gs;C:\gs\fonts                                           directories every time a new font is requested, this method in-
                                                                       creases startup time. To avoid inconsistencies, make sure there
or on Unix:                                                            is no Fontmap file in one of the GS_LIB directories if you use
set GS_LIB=/usr/local/share/ghostscript/fonts                          GS_FONTPATH, or launch Ghostscript with the -dNOFONT-
export GS_LIB                                                          MAP option.
For now, the font configuration is already done.
   Each directory in GS_LIB may contain the Fontmap file which         TrueType fonts. Starting with Version 4.0, Ghostscript con-
defines the relation between font names and file names. To add         tains a rasterizer for TrueType fonts. Note that Ghostscript sup-
new fonts, simply add a line similar to the following at the end       ports two flavors of TrueType fonts.
of the Fontmap file:                                                       Type 42 fonts: These contain TrueType data wrapped in
                                                                       PostScript instructions and can be directly processed by the in-
/Fontname       (filename) ;                                           terpreter. Type 42 capability is integrated in all Ghostscript con-
The file name in parentheses must be found in one of the font          figurations which include Level 2 support (which is the case for
directories. In many cases you can save yourself the trouble of        all default makefiles). Level 2 capable Ghostscript versions ac-
entering font and file names because there are prebuilt Fontmap        cept PostScript files with embedded Type 42 fonts (created, for
files for several systems and font configurations. If you use one      example, by the Windows PostScript driver).
of the following, simply copy the appropriate file to the name             Native TrueType files: Files in TTF format (as installed under
Fontmap:                                                               Windows) contain raw TrueType data which a PostScript inter-
                                                                       preter generally cannot process directly. Ghostscript, however,
File name        Origin of fonts/name of operating system              contains some additional code for interpreting raw TrueType
Fontmap.atm      Windows with standard ATM fonts                       files. This code is activated by the “ttfont” makefile option.
Fontmap.atb      Adobe Type Basics font package                        Since TrueType plays an important role for Windows users, the
Fontmap.gs       URW++ fonts (standard fontmap)                        Windows Ghostscript version is configured with the “ttfont”
Fontmap.os2      OS/2 with integrated ATM                              feature by default. This means that the Windows TrueType font
Fontmap.osf      DEC OSF/1 with DPS                                    directory can be configured for use with Ghostscript just as any
Fontmap.sol      Solaris 2.3 and higher with DPS                       PostScript font directory. However, Ghostscript only recognizes
Fontmap.ult      Ultrix 4.3 and higher with DPS                        TTF font files when searching font files via the GS_FONTPATH
Fontmap.vms      VAX/VMS with DECwindows/Motif and DPS                 variable; it’s not possible to process TrueType files via the
 Ghostscript User Manual                                                                                    Chapter 2: Installing Ghostscript   8
“run” operator. You can work around this with the following             3 Building Ghostscript from C Source
instruction:
                                                                          Since the C source code of Ghostscript is readily available, you
(file.ttf) (r) file .loadttfont
                                                                          can build an executable version of the interpreter if you have a
Platform fonts on Windows and X11. Ghostscript always                     C compiler for your system (and some experience in compiling
needs access to all PostScript fonts used in a document. It ras-          C programs). This way, you can link in additional drivers that
                                                                          are contained in the Ghostscript distribution but that (due to
terizes all the characters itself instead of delegating this task to
the operating system, ATM, or the X server (like other pro-               memory restrictions) are not compiled into the standard ver-
grams do). However, to speed up processing, Ghostscript                   sions. More adventurous programmers also have the chance to
                                                                          implement their own extensions to Ghostscript. The following
sometimes uses system fonts. This feature is called platform fonts
                                                                          sections will give an overview of the compilation process and
and is used only for certain font sizes and horizontal or vertical
                                                                          the configuration options.
text. Even so, the PostScript font name must exactly match the
system font name.
   For small font sizes, platform fonts generally improve screen       3.1 A Little Tour to Ghostscript Files
font representation. In some situations, however, they make it
                                                                           The Ghostscript source directory contains several hundred
worse – e.g., if PostScript and system font metrics don’t match
                                                                          files. The compilation may even double this number, so you
(which results in ugly formatting). Another problem affects
                                                                          may well get lost in this multitude of files. The following table
fonts with unusual character sets (encodings). In both cases you
                                                                          lists the most important file types contained in the Ghostscript
can turn off platform fonts by launching Ghostscript with the
                                                                          distribution:
-dNOPLATFONTS option. There is also a special X Window re-
source to achieve this:                                                   README, NEWS general information and development history of Ghostscript
Ghostscript*useExternalFonts:false                                        current.txt           notes on the current version
                                                                          new-user.txt          overview of Ghostscript
                                                                          use.txt               information on using Ghostscript
                                                                          devices.txt           Details on a number of printer drivers
                                                                          make.txt              notes on compiling Ghostscript
                                                                          other *.txt           additional documentation on special topics
                                                                          PUBLIC                “Aladdin Ghostscript Free Public License” (licensing conditions)
                                                                          *.1                   several Unix-style manual pages
                                                                          *.c, *.h, *.asm       source files
                                                                          *.mak, *.def, *.rc,   auxiliary files for building the program
                                                                          *.icx
                                                                          *.sh, *.bat, *.cmd    scripts and batch files used in the build process; several special
                                                                                                applications of Ghostscript
                                                                          gs_*.ps               initialization files for Ghostscript
                                                                          pdf_*.ps              initialization files for the PDF interpreter
                                                                          other *.ps            auxiliary PostScript files and sample programs
                                                                          Fontmap.*             Fontmap files for several systems
 Ghostscript User Manual                                                                                       Chapter 3: Building Ghostscript from C Source         9
3.2 Compiling the Standard Version                                        directories of the Ghostscript directory. The -d option of pkun-
                                                                          zip creates the directory gs5.xx:
   Requirements. To build Ghostscript, you need approximate-              pkunzip -d gs5xxsr1.zip
   ly 16 MB disk space. The source is written in ANSI-C suited for        pkunzip -d gs5xxsr2.zip
   most current C compilers. However, you can also use an old             pkunzip -d gs5xxsr3.zip
                                                                          cd gs5.xx
   Kernighan & Ritchie compiler. The auxiliary program ansi2knr
                                                                          mkdir jpeg-6a
   converts the source files to K&R syntax before compilation. An-        cd jpeg-6a
   other auxiliary program called genarch automatically creates an        pkunzip ..\..\jpeg-6a.zip
   include file which describes hardware and compiler architec-           cd ..
                                                                          mkdir libpng
   ture. This includes bit and byte ordering, word size, and other        cd libpng
   system-specific information. Ghostscript can be compiled on            pkunzip ..\..\lpngxxx.zip
   MS-DOS, Windows, OS/2, Amiga, many Unix systems, Macin-                cd ..
                                                                          mkdir zlib
   tosh, and VMS. The C source is highly portable, so compiling it        cd zlib
   on new systems shouldn’t be much of a problem.                         pkunzip ..\..\zlibxxx.zip
      If you want to customize your particular version of Ghost-          cd ..
   script, see section 3.3 for a description of options you may set       The Ghostscript distribution contains makefiles for the Mi-
   before compiling the program.                                          crosoft, Borland, Watcom and other C compilers (see make.txt).
                                                                          For example, to create the 32-bit Windows version of Ghost-
   Makefiles. The compilation process is controlled by make-              script using the Borland Compiler, you first have to create the
   files which you can adapt as necessary. To improve legibility,         makefile:
   the makefiles are split in parts:
                                                                          echo !include "bcwin32.mak" >makefile
   gs.mak       Ghostscript “core” source
                                                                          Next, you can change some settings in bcwin32.mak, e.g., com-
   lib.mak      graphics library
                                                                          piler and Ghostscript paths, optimizations for 386/486/586
   int.mak      interpreter
                                                                          CPUs or FPU, assembler accelerator modules or debugging op-
   devs.mak     device drivers
                                                                          tions. Finally, launch make. In an intermediate step you have to
   jpeg.mak     JPEG library
                                                                          manually start the Windows program genarch to create a system
   libpng.mak   PNG graphics file format library
                                                                          specific include file.
   zlib.mak     compression routines used for the PNG format
                                                                          Compiling on Unix. You need the following archive files for
   All other *.mak files are platform specific makefiles used to con-     compiling Ghostscript: ghostscript-5.xx.tar.gz, jpeg-6a.tar.gz, lib-
   figure the development system. The compilation process for             png-x.xx.tar.gz, and zlib-1.x.x.tar.gz. Note that the additional li-
   different platforms and the supported development systems are          braries may also be available by other names at Ghostscript dis-
   described in full detail in the file make.txt. The following de-       tribution points. Decompress the C source for Ghostscript and
   scription is not intended to replace this file, but to give you a      the JPEG, PNG, and ZLIB libraries from the compressed tar ar-
   jump start.                                                            chives into a suitable directory. The tar commands create the
                                                                          gs5.xx directory:
   Compiling on MS-DOS, Windows, OS/2. First decompress
                                                                          gunzip -c   ghostscript-5.xx.tar.gz | tar xvf -
   the C source from the compressed archive files gs5xxsr1.zip,
                                                                          cd gs5.xx
   gs5xxsr2.zip, and gs5xxsr3.zip. The files in the other archive files   gunzip -c   ../jpeg-6a.tar.gz | tar xvf -
   jpeg-6a.zip, lpngxxx.zip, and zlibxxx.zip contain additional librar-   gunzip -c   ../libpng-x.xx.tar.gz | tar xvf -
   ies needed by Ghostscript. These are unpacked into three sub-          gunzip -c   ../zlib-1.x.x.tar.gz | tar xvf -
    Ghostscript User Manual                                                                         Chapter 3: Building Ghostscript from C Source   10
mv libpng-x.x.x libpng                                                   Compiling on the Macintosh. In addition to the source
mv zlib-x.xx zlib                                                        code in MS-DOS or Unix format, you need the archive macgs-
The mv commands are necessary because the tar archives in-               v1.0-src.sit.hqx to compile Ghostscript for the Mac. This ar-
clude directory names containing the version numbers.                    chive contains some additional Macintosh-specific files. The
The Ghostscript distribution contains makefiles for several op-          source files end up in several folders. You’ll find an overview of
erating systems and compilers (ANSI-C, Kernighan&Ritchie,                the build process in the Mac GS Viewer Manual (part of the
and GNU-C). Choose the appropriate makefile from *.mak and               Ghostscript files) and some hints for compiling with the MPW
create a symbolic link with the following command (assuming              or CodeWarrior compilers in the file worksheet.
you use the GNU compiler):
ln -s unix-gcc.mak makefile                                              Compiling on other systems. The file readme contains
                                                                         some remarks on Ghostscript ports to other systems, including
Use unixansi.mak or unix-cc.mak, respectively, for an ANSI or
                                                                         VMS, Amiga, Atari ST, Acorn Archimedes and NEXTSTEP.
K&R compiler. On some systems you have to adapt the search
path for X11 specific include files and additional libraries. These
are controlled by the XINCLUDE und LDFLAGS variables in               3.3 Configuration Options and Drivers
the makefile which you can change before launching make. By              You can adjust the Ghostscript makefile to build a version that
changing the prefix variable in the makefile you can adapt the           suits your needs with several extensions and an individual as-
install directory. Now compile and install Ghostscript with the          sortment of drivers. The most important options are PostScript
command                                                                  Level 1, PostScript Level 2, and PDF. You can use the FEAT-
make install                                                             URE_DEVS variable in the makefile to control the interpreter’s
 Consult the make.txt file if you have trouble with the build pro-       configuration. The following table lists the most commonly
cess. The install process needs root permission on most systems.         used features:
After compiling Ghostscript, the install command copies the ex-
                                                                          level1   PostScript Level 1
ecutable program to /usr/local/bin and the auxiliary files to /usr/
                                                                          level2   PostScript Level 2
local/share/ghostscript/5.xx. To complete the installation, you
                                                                          pdf      Portable Document Format (PDF)
have to install fonts for Ghostscript as described in section 2.5,
                                                                          ttfont   Support for native TrueType font files
»Font Configuration«.
                                                                          epsf     Support for Encapsulated PostScript files (EPS) with binary header
Compiling and installing Ghostview. Now you should in-
stall and compile the Ghostview source. This is accomplished             By default, PostScript Level 2 and PDF support are configured
with the commands                                                        for all 32-bit configurations except the older Macintosh 3.33
                                                                         port. The Windows configuration additionally contains the
gunzip -c ghostview-1.5.tar.gz | tar xvf -
cd ghostview-1.5                                                         ttfont feature.
xmkmf                                                                        Another important configuration option relates to the set of
make                                                                     included drivers. Since it is not possible to load Ghostscript
make install
                                                                         drivers dynamically at runtime, you have to choose the driver
If your system doesn’t have the xmkmf program, you have to               set when building the program. In doing so, you trade function-
adapt the Ghostview makefile manually (this shouldn’t be too             ality for memory efficiency: If all available drivers were includ-
hard if you have ever worked with makefiles).                            ed in Ghostscript, the program would need far too much mem-
                                                                         ory. For this reason the standard configuration for each
                                                                         platform contains only the most important screen, printer, and
 Ghostscript User Manual                                                                                 Chapter 3: Building Ghostscript from C Source   11
file format drivers for the respective platform. You can check          Display drivers in Ghostscript 5.01
the list of available Ghostscript drivers using the command line        Advanced Logic chipset SuperVGA                          ali        –
gs -?                                                                   ATI Wonder SuperVGA, 256 colors                          atiw       D
                                                                        AT&T 3b1/Unixpc monochrome display                       att3b1     –
If you want Ghostscript to use a driver for which C source is in-
                                                                        Borland Graphics Interface                               bgi        –
cluded in the distribution but which is not compiled into the ex-
                                                                        CRT sixels, e.g. VT240 compatible terminals              sxlcrt     –
ecutable by default, you have to build your own version by us-          EGA 640x350, 16 colors                                   ega        D
ing a modified makefile.                                                Hercules Graphics Display                                herc       –
    Many Ghostscript drivers have been contributed by users             Linux PC with VGALIB                                     vgalib     –
and later became part of the Ghostscript distribution. If you           Linux PC with VGALIB, 256 colors                         lvga256    –
want to write a new driver, read the remarks on Ghostscript/            Macintosh window (QuickDraw)                             mac        M
driver interaction in drivers.txt.                                      Microsoft Windows DLL                                    mswindll   W
    In addition to the file format drivers listed in the table below,   OS/2 DLL bitmap                                          os2dll     O
previous Ghostscript versions contained one for the GIF graph-          OS/2 Presentation Manager                                os2pm      O
ics file format. In reaction to the licensing problems around the       Private Eye display                                      pe         –
                                                                        Sony Microsystems monochrome display                     sonyfb     –
LZW compression technique used in GIF, Peter Deutsch
                                                                        SunView window system                                    sunview    –
dropped support for this format from the Ghostscript distribu-
                                                                        SuperVGA with S3 Chip 86C911                             s3vga      –
tion. If you have to create GIF files you can integrate the GIF
                                                                        SuperVGA 800x600, 16 colors                              svga16     D
driver from an older release. However, it’s easier to render to         SuperVGA with Tseng Labs ET3000/4000 Chip, 256 colors    tseng      D
another graphics file format (e.g., TIFF or PNG) and convert it         SuperVGA with VESA driver                                vesa       –
to GIF using a graphics converter.                                      Trident SuperVGA, 256 colors                             tvga       D
    The tables on the next pages list all display, printer, and file    VGA 640x480, 16 colors                                   vga        D
format drivers available for Ghostscript 5.01. Each line contains       X Window System (X11), release 4 and higher              x11        U
a description of the device or format and the short name of the         X Window System as alpha device                          x11alpha   U
driver. The last column in the table tells you on which of the fol-     X Window System as CMYK device, 1 bit per color          x11cmyk    U
lowing platforms the particular driver is part of the standard          X Window System as b/w device                            x11mono    U
configuration:
                                                                        Printer drivers in Ghostscript 5.01
D        MS-DOS 386 with 32-bit extender
                                                                        Apple Dot Matrix printer (also for Imagewriter)          appledmp   –
W        Windows 32-bit
                                                                        Apple Imagewriter, high resolution                       iwhi       –
O        OS/2
                                                                        Apple Imagewriter, low resolution                        iwlo       –
U        Unix
                                                                        Apple Imagewriter LQ, 320 x 216 dpi                      iwlq       –
M        Mac GS Viewer (Ghostscript version 3.33)
                                                                        CalComp raster format                                    ccr        –
                                                                        Canon BubbleJet BJ10e                                    bj10e      DWOU
The driver name is used in the makefile as well as for selecting a      Canon BubbleJet BJ200                                    bj200      DWOU
driver within Ghostscript. The makefile variables                       Canon Color BubbleJet BJC-600 and BJC-4000               bjc600     DWOU
DEVICE_DEVS1 to DEVICE_DEVS15 contain the names of the                  Canon Color BubbleJet BJC-800                            bjc800     DWOU
drivers to be included in the program. If you don’t supply a            Canon LBP-8II laser printer                              lbp8       WO
driver name at startup, Ghostscript uses the first driver in its list   Canon LIPS III laser printer with CaPSL                  lips3      –
(which is a display driver on all platforms).                           Mitsubishi CP50 color printer                            cp50       –
                                                                        DEC LA50                                                 la50       –
                                                                        DEC LA70                                                 la70       –
 Ghostscript User Manual                                                                                Chapter 3: Building Ghostscript from C Source   12
DEC LA70 with low resolution extensions                    la70t      –       OCE 9050                                                    oce9050     –
DEC LA75                                                   la75       –       Okidata IBM-compatible dot matrix printer                   okiibm      –
DEC LA75plus                                               la75plus   –       Okidata MicroLine 182                                       oki182      –
DEC LJ250 Companion color printer                          lj250      WO      OS/2 system printer driver (only for OS/2 DLL)              os2prn      –
DEC LJ250, alternate driver                                declj250   WO      Ricoh 4081 laser printer                                    r4081       WO
DEC LN03                                                   ln03       –       Sony Microsystems NWP533 laser printer                      nwp533      –
Epson AP3250                                               ap3250     –       StarJet 48 inkjet printer                                   sj48        –
Epson-compatible dot matrix printer (9 or 24 pin)          epson      DWO     SPARCprinter                                                sparc       –
Epson-compatible 9-pin, intermediate resolution            eps9mid    WO      Tektronix 4693d color printer, 2 bits per RGB component     t4693d2     WO
Epson-compatible 9-pin, triple resolution                  eps9high   DWO     Tektronix 4693d color printer, 4 bits per RGB component     t4693d4     WO
Epson LQ-2550 and Fujitsu 3400/2400/1200 color printers    epsonc     WO      Tektronix 4693d color printer, 8 bits per RGB component     t4693d8     WO
Epson LP-8000 laser printer                                lp8000     –       Tektronix 4695/4696 inkjet plotter                           tek4696    WO
Epson Stylus Color                                         stcolor    WOM     Unified printer driver for many printers, e.g. NEC Pinwriter uniprint   –
Epson Stylus 800                                           st800      WO      P2X (ESC/P), Epson Stylus Color (ESC/P2), HP Deskjet
                                                                              550C (HP-RTL). See devices.txt for details.
HP DesignJet 650C                                          dnj650c    –
                                                                              Xerox XES 2700, 3700, 4045, and others                       xes        –
HP DeskJet and DeskJet Plus                                deskjet    DWOU
HP DeskJet 500                                             djet500    DWOU
HP DeskJet 500C, 1 bit per pixel                           cdeskjet   DWOU    Fax and other raster file format drivers in Ghostscript 5.01
HP DeskJet 500C, 24 bit per pixel, also for DeskJet 540C   cdjcolor   DWOU
                                                                              BMP monochrome                                              bmpmono     WO
HP DeskJet 500C (same as cdjcolor)                         cdj500     –
                                                                              BMP 4 bits (EGA/VGA)                                        bmp16       WO
HP DeskJet 500C (not for 550C/560C), alternate driver      djet500c   WO
                                                                              BMP 8 bits                                                  bmp256      WO
HP DeskJet 500C b/w, also for DeskJet 510, 520, 540C       cdjmono    DWOU
                                                                              BMP 24 bits                                                 bmp16m      WO
HP DeskJet 550C/560C                                       cdj550     DWOUM
                                                                              CGM b/w, low level output only                              cgmmono     –
HP LaserJet                                                laserjet   DWOU
                                                                              CGM 8 bits, low level output only                           cgm8        –
HP LaserJet Plus                                           ljetplus   DWOU
                                                                              CGM 24 bits, low level output only                          cgm24       –
HP LaserJet IId/IIp/III* with TIFF compression             ljet2p     DWOU
                                                                              CIF file format for VLSI                                    cif         –
HP LaserJet III* with delta row compression                ljet3      DWOU
                                                                              DigiBoard DigiFAX, high resolution                          dfaxhigh    O
HP LaserJet IIID with duplex function                      ljet3d     –
                                                                              DigiBoard DigiFAX, low resolution                           dfaxlow     O
HP LaserJet 4, 600 dpi                                     ljet4      DWOU
                                                                              Fax group 3, with EOLs, no header or EOD                    faxg3       U
HP LaserJet 4 with Floyd-Steinberg dithering               lj4dith    –
                                                                              Fax group 3 2-D, with EOLs, no header or EOD                faxg32d     U
HP PaintJet XL                                             pj         DWOU
                                                                              Fax group 4, with EOLs, no header or EOD                    faxg4       U
HP PaintJet XL, alternate driver                           pjetxl     –
                                                                              ImageMagick MIFF format, 24 bit color (RLE compressed)      miff24      –
HP PaintJet XL color printer                               pjxl       DWOU
                                                                              JPEG format with JFIF header, RGB output                    jpeg        DWOU
HP PaintJet XL color printer, alternate driver             paintjet   –
                                                                              JPEG format with JFIF header, gray output                   jpeggray    DWOU
HP PaintJet XL 300 color printer, also for DeskJet 1200C   pjxl300    DWOU
                                                                              MGR devices, 1 bit monochrome                               mgrmono     –
HP 2563B line printer                                      lp2563     –
                                                                              MGR devices, 2 bits gray scale                              mgrgray2    –
IBM Proprinter, 9 pin                                      ibmpro     DWO
                                                                              MGR devices, 4 bits gray scale                              mgrgray4    –
IBM Jetprinter inkjet color printer (Modell #3852)         jetp3852   WO
                                                                              MGR devices, 8 bits gray scale                              mgrgray8    –
Imagen ImPress                                             imagen     –
                                                                              MGR devices, 4 bits color                                   mgr4        –
C. Itoh M8510                                              m8510      WO
                                                                              MGR devices, 8 bits color                                   mgr8        –
Microsoft Windows system printer driver (DDB)              mswinprn   W
                                                                              PCX, 4 bit CMYK                                             pcxcmyk     –
Microsoft Windows system printer driver (DIB)              mswinpr2   W
                                                                              PCX, monochrome                                             pcxmono     DWOUM
Mitsubishi CP50 color printer                              cp50       –
                                                                              PCX, 8 bits gray scale                                      pcxgray     DWOUM
NEC P6/P6+/P60, 360 x 360 DPI                              necp6      WO
                                                                              PCX, 4 bits color                                           pcx16       DWOUM
Ghostscript User Manual                                                                                        Chapter 3: Building Ghostscript from C Source   13
PCX, 8 bits color                                     pcx256       DWOUM    4 Ghostscript Primer
PCX, 24 bits color                                    pcx24b       DWOUM
PKM(Portable Inkmap),CMYK internally,RGB output,ASCII pkm          U          This section is meant to give you a jump start into directly using
PKM, (raw format)                                     pkmraw       U          Ghostscript. If you use GSview or Ghostview to drive Ghost-
Plain bits (raw format), monochrome                   bit          DWOU       script, you only have to configure the appropriate Ghostscript
Plain bits (raw format), RGB                          bitrgb       DWOU       call; the rest is handled by the frontend.
Plain bits (raw format), CMYK                         bitcmyk      DWOU
PBM (Portable Bitmap), ASCII format                   pbm          UM
PBM, raw format                                       pbmraw       UM
                                                                           4.1 Launching Ghostscript
PGM (Portable Graymap), ASCII format                    pgm        UM         In the following examples, gs always represents the name of the
PGM, raw format                                         pgmraw     UM         Ghostscript executable file. Depending on your platform, the
PGM, optimizing to PBM ASCII if possible                pgnm       U
                                                                              actual name may vary.
PGM, optimizing to PBM raw if possible                  pgnmraw    U
PNG (Portable Network Graphics), monochrome             pngmono    WOU
                                                                              File search path. First you have to make sure that Ghost-
PNG (Portable Network Graphics), 8 bits gray scale      pnggray    WOU
                                                                              script finds its initialization and font files. When searching for
PNG (Portable Network Graphics), 4 bits color           png16      WOU
PNG (Portable Network Graphics), 8 bits color           png256     WOU
                                                                              files without an absolute file name, Ghostscript uses the follow-
PNG (Portable Network Graphics), 24 bits color          png16m     WOU        ing search order:
PPM (Portable Pixmap), ASCII format (RGB)               ppm        UM          ➤ The current directory.
PPM, raw format (RGB)                                   ppmraw     UM          ➤ The directories listed at the -I command line option, e.g., on
PPM, optimizing to PGM ASCII or PBM ASCII if possible   pnm        U              MS-DOS, Windows or OS/2:
PPM, optimizing to PGM raw or PBM raw if possible       pnmraw     U
                                                                                    gs -Id:/gstools/gs5.xx;d:/gstools/gs5.xx/fonts
SGI RGB pixmap format                                   sgirgb     –
TIFF b/w, CCITT RLE 1-dim (fax group 3 without EOLs)    tiffcrle   DWOU          or on Unix:
TIFF b/w, fax group 3 (with EOLs)                       tiffg3     DWOU             gs -I/usr/local/lib/gs:/usr/local/psfonts
TIFF b/w, fax group 3 2-D                               tiffg32d   DWOU
TIFF b/w, fax group 4                                   tiffg4     DWOU        ➤ Thedirectories listed in the GS_LIB environment variable.
TIFF b/w, LZW (compression tag 5)                       tifflzw    DWOUM       ➤ Predefineddirectories selected at build time using the
TIFF b/w, PackBits (compression tag 32773)              tiffpack   DWOUM         GS_LIB_DEFAULT makefile variable (C:\gs on MS-DOS,
TIFF 12 bit RGB color (no compression)                  tiff12nc   DWOU          Windows, or OS/2; /usr/local/share/ghostscript/5.xx on Unix).
TIFF 24 bit RGB color (no compression)                  tiff24nc   DWOU
                                                                              Watch the tiger. Ghostscript accepts the names of the Post-
PostScript, PDF, and PCL XL file format drivers in Ghostscript 5.01           Script files to display or print:
Encapsulated PostScript (EPS)                           epswrite   WU         gs file1.ps file2.ps ...
Portable Document Format (PDF)                          pdfwrite   DWOU       The interpreter processes the files one after the other. Then,
PostScript Level 1, monochrome bitmap                   psmono     DWOU       Ghostscript prompts for PostScript commands:
PostScript Level 1, 8-bit gray                          psgray     DWOU
“Vector” PostScript (not rasterized)                    pswrite    WU         GS>
HP PCL XL mono                                          pxlmono    WU         At this prompt you can type PostScript operators. If it is clumsy
HP PCL XL color                                         pxlcolor   WU         or uncommon to pass file names on the command line (e.g., on
                                                                              Windows), you can open files with the run command at the
                                                                              prompt. Try the tiger.ps sample file included in the Ghostscript
                                                                              distribution:
 Ghostscript User Manual                                                                                             Chapter 4: Ghostscript Primer   14
GS>(tiger.ps) run                                                         gs -sDEVICE=laserjet -sOutputFile=\|lp file.ps -c quit
On the Mac, it’s even easier to use the “File”, “Open” menu               Finally, Ghostscript sends the printer data to its standard out-
command.                                                                  put with the following command line (the -q option suppresses
   Note concerning MS-DOS path names: Since the backslash                 messages):
“\” escapes the next character in PostScript strings, you have to         gs -q -sOutputFile=- file.ps -c quit | lp
use double backslashes in path names. However, a single Unix-
                                                                          On Windows and OS/2 the easiest way to redirect printer data
style slash “/” also works as a separator in path names, for ex-
                                                                          is to use GSview. This frontend presents a menu for choosing
ample
                                                                          the printer interface.
GS>(c:/gs/tiger.ps)run
The following command exits the interpreter:                              Page size. Ghostscript uses U.S. letter size by default. To
                                                                          change this, use a text editor to locate the following line in the
GS>quit
                                                                          initialization file gs_init.ps:
Alternatively, you can append -c quit or -dBATCH to the com-
mand line.                                                                % (a4) /PAPERSIZE where { pop pop } { /PAPERSIZE exch
                                                                              def } ifelse
Selecting a driver. Usually, Ghostscript uses the first driver            In this line, remove the “%” comment sign at the beginning to
in its internal list (configured at build time). This driver outputs      use A4 format. You can also replace the “a4” in parentheses by
to the screen in the standard configurations on all operating             any other known format. A list of all formats known to Ghost-
systems. You can select another driver on the command line:               script (and their dimensions) can be found in the gs_statd.ps file.
                                                                          Alternatively, you can change the page size on the Ghostscript
gs -sDEVICE=laserjet file.ps -c quit
                                                                          command line:
This instructs Ghostscript to produces output for the particular
                                                                          gs -sPAPERSIZE=legal file.ps
device or file format (laserjet in the example above). Using the
following commands at the Ghostscript prompt, you can
change the driver at any time:                                         4.2 Printing with Ghostscript
GS>(epson) selectdevice                                                   Printing on MS-DOS. The following call processes a Post-
GS>(file.ps) run                                                          Script file for output on a Laserjet 4 printer connected to the
For printers with multiple resolutions you can also set the de-           parallel interface:
sired print resolution using the -r option:                               gs386 -q -dNOPAUSE -sDEVICE=ljet4 file.ps -c quit
gs -sDEVICE=epson -r60x72 -c quit                                         The -c quit option is used to exit Ghostscript after the PostScript
                                                                          file is completely rendered. Due to the -q option, Ghostscript it-
Redirecting printer data. On MS-DOS, Ghostscript sends
                                                                          self works quietly. However, the 386 MS-DOS extender still
printer data directly to the parallel port. On Unix, the printer
                                                                          presents its copyright banner. You can suppress it with an envi-
data is sent to a temporary file. You can also redirect it to your
                                                                          ronment variable:
own print file:
                                                                          set DOS4G=quiet
gs -sDEVICE=laserjet -sOutputFile=laserjet.prn file.ps
   -c quit                                                                If your printer is not connected to the parallel interface or you
If the output file name contains the variable %d (e.g. laser%d.           want to bring the printer data to another machine, you can redi-
prn), Ghostscript produces one output file per page and replac-           rect it to a file:
es the %d with the page number. On Unix, you can also redirect            gs386 -q -dNOPAUSE -sDEVICE=ljet4 -sOutputFile=ljet.prn
the data to a pipe using the “\|” syntax:                                     file.ps -c quit
 Ghostscript User Manual                                                                                          Chapter 4: Ghostscript Primer   15
               To print this file, send it to the printer interface with the copy    Printing on Unix. On Unix systems it’s possible to integrate
               command:                                                              Ghostscript in the printing process seamlessly. However, some
               copy /b ljet.prn lpt1:                                                experience with Unix systems administration is required. The
                                                                                     variety of available Unix derivatives doesn’t really simplify the
               The /b (binary) option is important because otherwise the copy
                                                                                     task of describing the integration of a PostScript emulation for
               command may not completely transfer the printer data.
                                                                                     printers. The following notes are not supposed to be a complete
                                                                                     description, but should help you get started.
               Printing on Windows 3.x. On Windows, it is easiest to use
                                                                                        Assuming other system components (especially spooler and
               GSview for printing with Ghostscript. After installing this
                                                                                     backend) are already set up correctly and are able to transfer bi-
               Ghostscript frontend correctly, you can select a PostScript file
                                                                                     nary data to the printer unmodified, you can manually use
               using “File”, “Print...”. In the subsequent menus you can select
                                                                                     Ghostscript for printing:
               printer driver, resolution (if the printer supports multiple reso-
               lutions), and – in the case of DSC compatible files – the page        gs -q -dNOPAUSE -sDEVICE=ljet4 -sOutputFile=\|lp
                                                                                         file.ps -c quit
               range you want to print. When Ghostscript has finished pro-
               cessing the file, you can select the printer interface for forward-   You can find hints on integrating Ghostscript in systems with a
               ing the data in a dialog box.                                         printcap database in the file unix-lpr.txt. The accompanying
                                                                                     shell script lprsetup.sh automatically creates some necessary di-
               Printing on Windows 95 and NT. For the newer systems of               rectories and links as well as printcap entries. Use a text editor
               the Windows family you can use the methods described above            to adapt the list of device drivers in this script that Ghostscript
               for MS-DOS and Windows 3.x. Additionally, you can select a            is supposed to use. Obviously, these drivers must be compiled
               printer queue using its UNC name:                                     into the Ghostscript executable. You can also set up additional
                                                                                     printcap filters with lprsetup.sh. By default, it creates an input
               gswin32 -q -dNOPAUSE -sDEVICE=ljet4 file.ps
                   -sOutputFile="\\spool\<printer name>" -c quit                     filter consisting of a shell script with the actual Ghostscript call.
               This spools the printer data to the given printer queue. Using            After executing lprsetup.sh, follow the instructions in unix-
               the -sOutputFile="\\spool" option instructs Ghostscript to            lpr.txt, i.e., create some links as indicated in the file, integrate
               present a dialog box in which you can select the desired printer      the generated printcap.insert file into the system printcap, and
               queue or interface. Again – it’s much easier to use GSview.           adjust the new entries to your local setup (serial interface pa-
                                                                                     rameters, etc.). The /usr/local/lib/ghostscript/filt directory con-
                                                                                     tains several links to the unix-lpr.sh file. In this file you have to
                  Fig. 6.
GSview simplifies select-                                                            add the -I option if you didn’t install Ghostscript in the stan-
       ing print drivers,                                                            dard directories.
options, and parameters.
                                                                                         On System V, Release 4, and related systems you can define
                                                                                     print filters for specific file types. The spooler launches these fil-
                                                                                     ters for printing on devices which are not supported directly.
                                                                                     To define Ghostscript as a filter, change to the directory /etc/lp/fd
                                                                                     and create a file for the printer, say ljet_ps.fd:
                                                                                     Input types: postscript,ps
                                                                                     Output types: simple
                                                                                     Command: /usr/local/bin/gs -sDEVICE=ljet4 -q
                                                                                     -sOutputFile=- -
                                                                                     Integrate this filter in the spool system:
                Ghostscript User Manual                                                                                       Chapter 4: Ghostscript Primer   16
   lpfilter -f ljet_ps -F /etc/lp/fd/ljet_ps.fd                          Like PostScript, you can also configure Ghostscript and GSview
   To print a PostScript file, simply declare the file type on the       as helper application for PDF files. Proceed as above, using the
   command line:                                                         pdf suffix and a MIME type of
   lp -T postscript tiger.ps                                             application/pdf
   For serial connections, make sure the backend doesn’t change          Note that Ghostview doesn’t yet directly support PDF.
   the printer data by using the stty options
                                                                         PostScript files and security. PostScript – being a full-
   -opost -cs8 -parenb
                                                                         blown programming language – contains operators for modify-
                                                                         ing and deleting files. This opens a security gap when down-
4.3 Ghostscript as Viewer for a WWW Browser                              loading unknown files. In the worst case, a file pretending to be
   World Wide Web browsers and many E-mail programs classify             a harmless PostScript image may delete files from your local
   files according to MIME types (Multipurpose Internet Mail Exten-      hard disk – possibly even with root permission! Although there
   sion). PostScript files use a MIME type of                            are no known cases of such “trojan horses”, you should protect
                                                                         yourself against this kind of attack. Ghostscript’s -dSAFER op-
   application/postscript
                                                                         tion disables critical file operators; the interpreter refuses to
   MIME types and corresponding viewers are generally config-            open files other than read-only. GSview launches Ghostscript
   ured in a configuration file or menu. The details vary according      with this option by default, Ghostview for Unix uses the option
   to the particular program. Let’s take a look at the Windows ver-      if launched with the -safer option itself.
   sion of the well-known Netscape WWW browser as an exam-
   ple:
    ➤ Launch Netscape Navigator.
    ➤ Choose “Options”, “General Preferences...” and the sub-
      menu “Helpers”.
    ➤ For the MIME type application/postscript enter ai, ps, eps in
      the extensions field (if the entry doesn’t exist already). Check
      “Launch the Application” for “Action” and enter the path of
      GSview, Ghostview oder Mac GS Viewer as appropriate,
      e.g., c:\gs\gsview32.exe.
    ➤ Click “OK” and “Options”, “Save Options”.
   Unix systems generally use the .mailcap file for configuring
   MIME types. Use the following entry for Ghostview (see below
   for the -safer option):
   application/postscript; ghostview -safer           %s
   The relation between MIME types and file extensions is con-
   trolled by the .mime.types file. If the following line doesn’t al-
   ready exist, add it to the .mime.types file:
   application/postscript        ai, ps, eps
    Ghostscript User Manual                                                                                    Chapter 4: Ghostscript Primer   17
 5 Ghostscript Reference Section                                        -Sname=string
                                                                        -sname=string
5.1 Command Line Options                                                Defines a name in systemdict with the given string definition
                                                                        (equivalent to /name (string) def).
   On all platforms, Ghostscript evaluates several command line
   options used to control the interpreter:                             -q
                                                                        (quiet) Suppress normal startup messages.
   -h
   -?                                                                   -f<filename>
   --help                                                               Execute the given file, even if its name begins with a “-” or “@”.
   These options cause Ghostscript to print a brief help message        -f provides a way to terminate the token list for -c.
   and a list of available (i.e., built-in) device drivers on screen.
                                                                        -g<number1>x<number2>
   @<filename>                                                          Equivalent to -dDEVICEWIDTH=number1 and -dDEVICE-
   Ghostscript reads the specified file and treats its contents the     HEIGHT= number2 (see below).
   same as the command line. This makes it easier to use com-
   mand line options on Windows or to use command lines longer          -r<number>
                                                                        -r<number1>x<number2>
   than 128 characters on MS-DOS.
                                                                        Equivalent to -dDEVICEXRESOLUTION=number1 and -dDE-
   -- <filename> arg1 ...                                               VICEYRESOLUTION=number2 (see below). This is intended for
   -+ <filename> arg1 ...                                               devices that support different horizontal and vertical resolu-
   Ghostscript treats the file name as usual but stores the remain-     tions, especially dot matrix printers.
   ing arguments in an array named ARGUMENTS in userdict.
   This way PostScript programs can access options and command          -u<name>
   line arguments.                                                      Undefines a name, cancelling -d or -s.
   -@ <filename> arg1 ...                                               -I<directories>
                                                                        Add a list of directories to the search path for initalization and
   Same as -- and -+, but expands arguments from argfile.
                                                                        font files. Multiple directories are separated with a semicolon
   -c tokens ...                                                        “;” (MS-DOS, Windows, OS/2) or colon “:” (Unix).
   Interprets arguments up to the next “-” as PostScript code and
   executes them. Each argument must be exactly one token.              -P
                                                                        Ghostscript first searches the current directory for library files.
   -Dname=token                                                         This is the default.
   -dname=token
   Defines a name in systemdict with the given definition (equiva-      -P-
   lent to /name token def). This option is mainly used for spe-        Ghostscript doesn’t search the current directory for library files,
   cial names (see below).                                              but uses the search path only.
   -Dname                                                               -
   -dname                                                               Instructs Ghostscript to read standard input from file or pipe
   Defines name in systemdict with a value of true.                     (instead of from the keyboard). Ghostscript reads and processes
                                                                        data from standard input and exits. Note that it’s not possible to
                                                                        read PDF files from standard input.
    Ghostscript User Manual                                                                            Chapter 5: Ghostscript Reference Section   18
Special PostScript names used as switches. The use.txt                garding the actual device resolution. Reasonable values for lpi
file contains some more options for debugging Ghostscript. A          are N/5 to N/20, where N is the resolution in dots per inch.
couple of names with special meanings is being interpreted by
the PostScript code in Ghostscript’s initialization files. They       -dFirstPage=<n>
                                                                      Starts interpreting on the given page of a PDF document.
work similar to command line options:
                                                                      -dGraphicsAlphaBits=<n>
-dBATCH
                                                                      Specifies the bit depth for graphics anti-aliasing. Possible values
Instead of displaying the interactive prompt after processing all
                                                                      are 1 (=no anti-aliasing), 2, and 4. Note that only few drivers are
command line files, Ghostscript exits. Equivalent to -c quit.
                                                                      capable of anti-aliasing.
-dCOLORSCREEN
On devices with at least 150 dpi resolution forces the use of sep-    -dFIXEDMEDIA
                                                                      Causes the media size to be fixed after initialization. Pages are
arate halftone screens with different angles for the process col-
                                                                      scaled or rotated if necessary.
ors (this produces the best quality output).
                                                                      -dFIXEDRESOLUTION
-dCOLORSCREEN=0
                                                                      Causes the output resolution to be fixed.
Uses separate screens with the same frequency and angle for
the process colors.                                                   -dLastPage=<n>
                                                                      Stops interpreting after the given page of a PDF document.
-dCOLORSCREEN=false
Forces the use of a single binary screen. If COLORSCREEN is           -dLOCALFONTS
not specified, the default is to use separate screens with differ-    This is a compatibility option for certain obsolete fonts. This op-
ent angles if the device has fewer than 5 bits per color.             tion makes Ghostscript load type 1 fonts always to local VM.
-dDELAYBIND                                                           -dNOBIND
Delay all bind operations until .bindnow is called. Used by the       Disables the bind operator (useful for debugging).
pstotext package.
                                                                      -dNOCACHE
-dDEVICEWIDTH=<number>                                                Disables the font cache (useful for debugging).
-dDEVICEHEIGHT=<number>
Sets width and height of the device, respectively (in pixels).        -dNOCIE
                                                                      substitutes DeviceGray and DeviceRGB for CIEBasedA and
-dDEVICEXRESOLUTION=<number>                                          CIEBasedABC color spaces respectively (useful on very slow
-dDEVICEYRESOLUTION=<number>                                          systems where color accuracy is less important).
Sets the device horizontal resp. vertical device resolution in dpi.
                                                                      -dNODISPLAY
-dDISKFONTS                                                           Suppresses normal initialization of the output device. This is
Causes character outlines in fonts to be loaded from disk on de-      useful for debugging and also for PostScript converters that
mand only. This slows down text rendering but increases the           don’t produce any screen or printer output (e.g., ps2ai).
number of fonts which may be loaded into RAM. This tech-
nique is mainly intended for low-memory systems.                      -dNOFONTMAP
                                                                      Suppresses loading of the Fontmap file(s).
-dDITHERPPI=<lpi>
forces all devices to be considered high-resolution, and forces       -dNOGC
use of a halftone screen or screens with lpi lines per inch, disre-   Disables the level 2 garbage collector (useful for debugging).
 Ghostscript User Manual                                                                             Chapter 5: Ghostscript Reference Section   19
-dNOPAUSE                                                                -sFONTMAP=<filename1>:<filename2>...
Disables the prompt and pause at the end of each page. This is           Defines one or more file names for the font file mapping table.
useful for producing printer output or driving Ghostscript from          Several file names are separated by a semicolon “;” under Win-
another program.                                                         dows and OS/2 and a colon “:” under Unix.
-dNOPLATFONTS                                                            -sFONTPATH=<dirname1>:<dirname2>...
Disables platform fonts for X Windows or Microsoft Windows               Defines one or more directory names to be searched for font
(see section 2.5, »Font Configuration«).                                 definitions. Several path names are separated by a semicolon
                                                                         “;” under Windows and OS/2 and a colon “:” under Unix.
-dNOPROMPT
Disables the prompt (but not the pause) at the end of each page.         -sOutputFile=<filename>
This prevents text and graphics output from being mixed on PC            Selects an output file name or pipe. If the file name contains the
displays.                                                                characters “%d”, Ghostscript replaces the “%d” with the actual
                                                                         page number and creates one file for each page, e.g., page%d.prn
-dORIENT1=false
                                                                         yields page1.prn, page2.prn and so on.
Exchanges the meaning of the values 0 and 1 for indicating
                                                                            On OS/2, Windows 95 and Windows NT you can use printer
page orientation with setpageparams. This is needed for the Post-
                                                                         queue names: -sOutputFile="\\spool\printername" sends
Script code of certain applications.
                                                                         the output to the named printer queue. If the printer name is
-dQUIET                                                                  missing, Ghostscript prompts for the name of the (connected)
Suppress informational messages. This is necessary when redi-            printer (Windows) or uses the default queue (OS/2).
recting device output to stdout.                                            On Unix, you can also redirect the output to another pro-
                                                                         gram via pipe: -sOutputFile=\|lp. The special name “-” for
-dSAFER                                                                  the output file instructs Ghostscript to send the data to its stan-
Disables the PostScript operators for writing or deleting disk
                                                                         dard output.
files. This is intended for using Ghostscript as viewer for a Web
browser in a secure mode.                                                -sPAPERSIZE=<papersize>
                                                                         Selects a page size, e.g., a4. The file gs_statd.ps contains a list of
-dSHORTERRORS                                                            supported page size names.
Brackets several error messages with %%[ and ]%% (as Adobe
Interpreters do).                                                        -sPSFile=<filename>
                                                                         Defines the output file name for PDF to PostScript conversion.
-dTextAlphaBits=<n>
Specifies the bit depth for text anti-aliasing. Possible values are      -sSUBSTFONT=<fontname>
1 (=no anti-aliasing), 2, and 4. Note that only few drivers are ca-      Selects the named font as substitute for all missing fonts. This
pable of anti-aliasing.                                                  disables Ghostscript’s normal font substitution mechanism.
-dWRITESYSTEMDICT
Systemdict remains writable. This is necessary for some utility       5.2 Environment Variables
programs that must bypass normal PostScript access protection,
                                                                         GS_DEVICE=<device>
such as font2c and pcharstr.                                             Defines the initial output device driver.
-sDEVICE=<device>                                                        GS_FONTPATH=<path>
Select the initial output device driver.                                 Specifies a list of directories that should be scanned for fonts at
                                                                         startup (see section 2.5, »Font Configuration«).
 Ghostscript User Manual                                                                                 Chapter 5: Ghostscript Reference Section   20
   GS_LIB=<path>                                                              Name                   Class                      Default value
   Search path for initialization and font files.                             maxDynamicColors       MaxDynamicColors           256
                                                                              useBackingPixmap       UseBackingPixmap           true
   GS_OPTIONS=<options>
                                                                              useXPutImage           UseXPutImage               true
   Defines a list of command line arguments to be processed be-
                                                                              useXSetTile            UseXSetTile                true
   fore the ones specified on the command line. All command line
                                                                              regularFonts           RegularFonts               (see use.txt)
   options are also allowed in this environment variable.
                                                                              symbolFonts            SymbolFonts                (see use.txt)
   TEMP=<directory>                                                           dingbatFonts           DingbatFonts               (see use.txt)
   Directory name for temporary files. On Windows and OS/2 this
   variable must point to an existing directory in order to have the          As an example, the resources below select a resolution of 72 dpi
   printing feature work properly.                                            (independent of actual screen size and resolution) and disable
   DOS4G=quiet                                                                platform fonts:
   Suppresses the usual startup message of the DOS extender for               Ghostscript*useExternalFonts:             false
   the 386 MS-DOS version.                                                    Ghostscript*xResolution: 72
                                                                              Ghostscript*yResolution: 72
                                                                              If you want Ghostscript to use the same resource settings every
5.3 X Window System Resources                                                 time, it’s best to put the resources into a file and load it with the
   Ghostscript evaluates several X resources under the program                xrdb program.
   name ghostscript and the class name Ghostscript. You can use X
   resources to define user preferences or to activate bug
                                                                           5.4 Configuration Error Messages
   workarounds for several X servers. In the use.txt file you can
   find more information on resources. The table below lists all re-          Ghostscript issues the usual PostScript error messages (see
   sources together with their default values.                                Chapter 2 of this book). Additionally, there are some messages
                                                                              relating to Ghostscript installation or configuration errors in-
   Name                       Class                   Default value           stead of PostScript errors:
   background                 Background              white
   foreground                 Foreground              black                   /undefinedfilename in (Fontmap)
   borderColor                BorderColor             black
                                                                              Ghostscript can’t find the Fontmap file, and the GS_FONTPATH
   borderWidth                BorderWidth             1
                                                                              environment variable isn’t set. Install a Fontmap file or set
   geometry                   Geometry                NULL
                                                                              GS_FONTPATH to point to an appropriate font directory.
   xResolution                Resolution              (calc. from screen      Can't find (or open) initialization file
                                                      size)
                                                                              gs_init.ps.
   yResolution                Resolution              (calc. from screen
                                                                              Ghostscript can’t find its main initialization file. Use the -I op-
                                                      size)
                                                                              tion or the GS_LIB enviroment variable to point Ghostscript to
   useExternalFonts           UseExternalFonts        true
                                                                              the directory containing the gs_*.ps files.
   useScalableFonts           UseScalableFonts        true
   logExternalFonts           LogExternalFonts        false                   Can't find (or can't open) font file xxx
   externalFontTolerance      ExternalFontTolerance   10.0                    The Fontmap file contains a font file entry for a nonexistent file
   palette                    Palette                 Color                   or a file that Ghostscript can’t open. Under Unix, check the file
   maxGrayRamp                MaxGrayRamp             128                     permissions.
   maxRGBRamp                 MaxRGBRamp              5
    Ghostscript User Manual                                                                                   Chapter 5: Ghostscript Reference Section   21
Substituting font Courier for xxx.                                      6 More Ghostscript Applications
Ghostscript can’t find a requested font and substitutes for it
with another font. Processing continues.                                  Many file format conversions and other special applications are
                                                                          possible with the help of Ghostscript drivers and auxiliary pro-
Unable to load default font xxx! Giving up.                               grams. Some of these applications are not PostScript interpreter
Ghostscript can’t find the default font file and hence isn’t able to      tasks at first sight. The descriptions in the following sections
do text output at all. Therefore processing stops. Check the font         provide a summary of the most important of these applications.
configuration.                                                            Usually you can find more detailed information in the appro-
                                                                          priate documentation or source files (*.txt, *.ps, *.c).
Can’t find library ’libXt.so.6’
Unix versions of Ghostscript generally are linked dynamically.
For this reason, several libraries must be accessible at runtime.      6.1 Graphics File Formats
Use the ldd command to find out which libraries are needed, lo-
                                                                          Displaying and printing graphics file formats. The utili-
cate these on your hard disk, and set the LD_LIBRARY_PATH
environment variable appropriately. Another solution is to link           ty programs viewcmyk.ps, viewgif.ps, viewjpeg.ps, view-
                                                                          pbm.ps, and viewpcx.ps – all written in PostScript – display or
Ghostscript statically.
                                                                          print raster graphic files in the CMYK, GIF, JPEG, PBM, or PCX
Unknown device: xxx                                                       file formats without converting them to PostScript. Launch
Ghostscript has been launched with an unknown device driver               Ghostscript with the appropriate utility and load a graphics file
name. If you want to use drivers which are not available in the           using one of the procedures viewcmyk, viewGIF, viewJPEG,
standard configuration, you have to recompile and link Ghost-             viewpbm, or viewpcx, e.g.
script with the necessary drivers.
                                                                          gs viewjpeg.ps
                                                                          GS>(file.jpg) viewJPEG
gs: Interpreter revision (501) does not match
gs_init.ps revision (403).                                                Converting PostScript to raster graphics formats.
Ghostscript found an initialization file that doesn’t match the           Several file format drivers enable Ghostscript to convert Post-
program version. Make sure the GS_LIB environment variable                Script files to TIFF, PBM, PCX, BMP, etc., given the appropriate
or the -I command line option don’t point to an obsolete Ghost-           driver has been compiled into the Ghostscript executable. The
script version on your hard disk.                                         Ghostscript call contains the name of the driver and (optionally)
                                                                          the resolution. For example, to create a 600 dpi bitmapped TIFF
                                                                          version of a file, use the following command:
                                                                          gs -q -dNOPROMPT -dBATCH -sDEVICE=tiffpack -r600
                                                                             -sOutputFile=page%d.tif file.ps
                                                                          Ghostscripts replaces the “%d” variable in the filename with the
                                                                          actual page number (page1.tif, page2.tif etc.). By default, the TIFF
                                                                          drivers use a resolution of 204 x 196 dpi (standard fax resolu-
                                                                          tion).
                                                                          Enhanced rendering with anti-aliasing. A technique cal-
                                                                          led anti-aliasing tries to improve text or graphics rendering by
                                                                          making use of gray levels for smoothing. Anti-aliasing is imple-
                                                                          mented in a couple of Ghostscript drivers, namely the Windows
 Ghostscript User Manual                                                                                Chapter 6: More Ghostscript Applications   22
and OS/2 display drivers, as well as the Portable Graymap For-                If you configured and compiled Ghostscript with the epsf fea-
mat (PGM) and Portable Pixmap Format (PPM) driver. To make                 ture, the Interpreter is capable of reading EPS files which in-
use of anti-aliasing, the bit depth must be at least 8 bits. The fol-      clude binary screen preview sections in addition to the Post-
lowing command line can be used to convert a PostScript file to            Script code.
PGM with anti-aliasing:
                                                                           Converting to the Adobe Illustrator format. As of ver-
gs -q -dBATCH -sDEVICE=pgm -dTextAlphaBits=4
   -sOutputFile=file.pgm file.ps                                           sion 5.01, a special Ghostscript driver for creating Adobe Illu-
                                                                           strator format is not yet available. Instead, Ghostscript uses the
Possible alpha values are 1 (=no anti-aliasing), 2, and 4. Anti-           sophisticated PostScript program ps2ai.ps. Although this con-
aliasing for graphics can (independently of text anti-aliasing)            version is bound to some restrictions, in many cases it yields
similarly be achieved using the -dGraphicsAlphaBits=4                      graphics files which may be opened and edited with any Illus-
option.                                                                    trator-compatible program. On Unix, redirect Ghostscript’s out-
   Note: you can easily create anti-aliased output with GS-                put to a file. On Windows and OS/2 it’s easier to have Ghost-
view’s menu option “Media”, “Display Settings...”.                         script create the file directly. To achieve this, change the
                                                                           variable /jout at the beginning of ps2ai.ps to a value of true. As-
Converting PostScript to PostScript raster graphics.
                                                                           sign the name of the AI file you want to create to the /joutput
This conversion makes it possible to print PostScript Level 2
                                                                           variable. Now launch Ghostscript with the converter and the
files on devices with PostScript Level 1 interpreters. Ghost-
                                                                           PostScript file to be converted to AI format:
script’s psmono and psgray drivers produce PostScript files con-
taining a 1-bit or 8-bit raster version of the file as a PostScript        gs -dNODISPLAY ps2ai.ps file.ps
Level 1 bitmap. Similar to the TIFF conversion you can select              For EPS files that are missing the showpage operator at the end,
the resolution:                                                            you have to type this operator at the Ghostscript prompt before
gs -sDEVICE=psmono -r600 -sOutputFile=file1.ps file2.ps                    quitting in order to completely render the page. For the conver-
                                                                           sion to be successful, it is necessary for Ghostscript to have ac-
By default, the psmono driver uses a resolution of 300 dpi.
                                                                           cess to all fonts used in the PostScript file. Note that the conver-
                                                                           sion isn’t perfect: there may be problems concerning color
Converting PostScript to PostScript vector graphics..
The pswrite and epswrite drivers produce “high-level” Post-                ramps and grouped objects in the converted AI files.
                                                                              Unfortunately ps2ai.ps doesn’t work on the Mac.
Script or EPS output. Contrary to the above-mentioned Post-
Script drivers, this output isn’t rasterized but may contain geo-
metrical objects. Depending on the nature of the input file, the        6.2 PDF Files
output may increase or decrease in size. pswrite output may be
                                                                           Displaying and printing PDF files. You can list PDF files
considered as “purified” PostScript in some sense.
                                                                           on Ghostscript’s command line or in GSview’s open dialog box
Additional features for EPS files. The shell script/batch                  just like you can PostScript files because Ghostscript recognizes
                                                                           PDF files automatically. In order to be able to process PDF files,
file ps2epsi or ps2epsi.bat creates ASCII previews for EPSI files.
                                                                           Ghostscript must be configured with the PDF interpreter. By
Usage notes can be found in ps2epsi.txt. On Windows and OS/2
                                                                           default, this is true on all 32-bit systems except the Macintosh.
many additional EPS functions are possible with GSview, in-
cluding determining a correct bounding box and creating or de-             Ghostscript interprets the printable contents of PDF files only,
                                                                           and ignores hypertext elements (such as links, annotations, and
leting preview bitmaps. More details can be found in chapter 3
                                                                           bookmarks) and thumbnails. Although there is no font substitu-
of this book.
                                                                           tion with Multiple Master fonts, Ghostscript replaces a missing
 Ghostscript User Manual                                                                                 Chapter 6: More Ghostscript Applications   23
font with a similar one and adjusts the metrics of the substitut-       There are no further options available for PS to PDF conversion.
ed font to those of the missing font.                                   Ghostscript recognizes the pdfmark and setdistillerparams opera-
   Contrary to PostScript files, it’s possible to access random         tors. However, the distiller parameters are ignored with the ex-
pages of PDF files. Therefore you can select a page range for           ception of ASCII85 encoding. Text in any other font than the 14
PDF files when launching Ghostscript:                                   Acrobat base fonts or in fonts with non-standard encodings is
gs -dFirstPage=<n> -dLastPage=<m> file.pdf                              converted to bitmaps.
This works for displaying and printing PDF files and for con-           Encrypted PDF files. PDF files may optionally contain en-
verting them to PostScript (see below).                                 crypted data. PDF encryption uses a combination of the MD5
                                                                        and RC4 algorithms. Although code for these algorithms is
Converting PDF files to PostScript. Ghostscript is able to
                                                                        publicly available, current U.S. export regulations make it im-
convert PDF files back to PostScript Level 2. In fact, if the PDF
                                                                        possible to include the code necessary for reading encrypted
file doesn’t contain compressed raster graphics or color spaces,
                                                                        PDF files in the Ghostscript distribution. You may, however, re-
the generated PostScript files use Level 1 operators only. The
                                                                        trieve a simple add-on file from the following URL:
following command line creates the corresponding PostScript
file for a PDF file:                                                    http://www.ozemail.com.au/~geoffk/pdfencrypt
gs -dNODISPLAY -sPSFile=file.ps file.pdf                                Of course this file doesn’t contain a code-cracker: you still need
                                                                        the password to open encrypted PDF files.
A little shell script/batch file contained in the Ghostscript dis-
tribution makes this even easier:                                       PDF files in GSview and Ghostview. Note that because of
pdf2ps file.pdf file.ps                                                 the idiosyncrasies of the PDF format Ghostscript isn’t able to
The following additional options are available for PDF to Post-         read PDF files from its standard input. Due to this fact, display-
Script conversion:                                                      ing PDF files with Ghostview has its limitations. You can use
                                                                        the following command line for Ghostview on Unix to browse
-dPSBinaryOK                                                            PDF files one page after the other. It’s not possible to jump to
Allows the generated PostScript files to contain binary data.           arbitrary page numbers:
-dPSLevel1                                                              ghostview -arguments file.pdf quit.ps
Generates PostScript Level 1 output.                                    GSview for Windows and OS/2 has already been adapted to
-dPSNoProcSet                                                           processing PDF files. GSview handles PDF files just as Post-
Does not include the PostScript prolog (procset) in the output.         Script files. Jumping to an arbitrary page in the file is also
Note that the prolog is necessary when sending the generated            possible.
file to a PostScript printer.
                                                                        Extracting text from PDF files. Using the ps2ascii.ps or
Converting PostScript to PDF (distilling). Ghostscript is               pstotext utilities you can extract text from PDF files (see next sec-
also able to “distill” PostScript files to PDF. The following com-      tion for details).
mand line can be used to distill PostScript files to PDF:
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite                            6.3 Printing and Extracting Text
   -sOutputFile=file.pdf file.ps
                                                                        Printing text files. The gslp.ps utility program implements a
Again, a shell script/batch file simplifies the process:
                                                                        lineprinter emulation, i.e., printing simple text files with Post-
ps2pdf file.ps file.pdf                                                 Script commands. This includes some formating such as head-
 Ghostscript User Manual                                                                              Chapter 6: More Ghostscript Applications   24
ers and footers, page numbers and tabs. Ghostscript optionally            a different method will be used for text extraction which is less
creates PostScript code or renders the text on screen or printer.         accurate but faster. Note that unlike ps2ascii.ps, pstotext pre-
Details on using the emulator and possible options may be                 serves umlauts and other special characters.
found in the gslp.ps file. Example for printing a text file on a la-
serjet printer:
                                                                       6.4 Font Tools
gs -q -sDEVICE=laserjet -r300 -dNOPAUSE -- gslp.ps
    file.txt                                                              Printing font tables. The prfont.ps utility prints character ta-
You may use several options following the file name gslp.ps.              bles for any given PostScript font. It first prints all characters
The -p option creates a PostScript file instead of rendering the          contained in the encoding vector of the font, then uncoded
text on screen or printer:                                                characters. If the font isn’t configured in Ghostscript, enter the
gs -q -dNOPAUSE -- gslp.ps -p file.ps file.txt                            font file name on the Ghostscript command line. Then type the
                                                                          font name and the procedure name at the Ghostscript prompt:
Extracting text from PostScript and PDF files. The text                   gs fontfile prfont.ps
extraction feature is a counterpart of the lineprinter emulation          GS>/FontName DoFont
as it extracts the textual contents from a PostScript file. There
are at least two options for extracting text with Ghostscript: the
ps2ascii.ps PostScript program and the more sophisticated psto-
text package.
   ps2ascii.ps is included in the Ghostscript distribution. De-
pending on the -dSIMPLE option, the utility creates simple or
complex output. Simple output consists of text only, whereas
                                                                                                 And now
complex output additionally contains information about font                                      for a little commercial...
type and string positions. The positions are given in tenth of a
point. More details may be found at the beginning of ps2ascii.ps,
some usage samples in the batch file ps2ascii.bat. A typical com-
mand line:
gs -dNODISPLAY -dNOBIND -dWRITESYSTEMDICT -dSIMPLE
    ps2ascii.ps file.ps -c quit >file.txt
Note that there is good reason to call the utility ps2ascii: If the
PostScript file contains any special characters (German um-
lauts, for example), they don’t make their way into the output
file but get substituted with two-character sequences of ASCII
symbols.
    The pstotext package is available as a Ghostscript add-on
from the following URL:
http://www.research.digital.com/SRC/virtualpaper/
     pstotext.html
The pstotext code is also included in the GSview distribution as
a separate DLL. Simply use GSview’s “Edit”, “Text Extract...”
feature to make use of it. If you check “Options”, “Quick Text”,
 Ghostscript User Manual                                                                               Chapter 6: More Ghostscript Applications   25
                          PostScript & Acrobat/PDF
                          Applications, Troubleshooting, and Cross-Platform Publishing
                          Originally entitled the »PostScript and Acrobat Bible« in Ger-
                          man, this handbook achieves the seemingly impossible: it covers
                          this tricky and technical field in an entertaining manner without
                          getting bogged down in PostScript programming. The author
                          genuinely wants to assist in overcoming cross-platform barriers
                          using MS-DOS, Windows, Macintosh or Unix and, accordingly,
                          neither the book nor the tools are limited to one particular plat-
                          form or operating system. The 9 chapters plus 3 appendixes run
                          the entire gamut, from the very basics right up to Ghostscript.
                          The whole book is creatively designed, making use of comical
                          illustrations. In short, essential reading for all technically minded
                          users of PostScript and Acrobat/PDF.
                          Examples
                          •   How to port EPS files or fonts from Mac to Windows to Unix
                          •   Pros and cons of different PostScript drivers for Windows
                          •   How to install PostScript fonts in the X Window System
                          •   How to interpret and fix PostScript error messages
                          •   How to edit or create PostScript fonts
                          •   How to make EPS files editable again
                          •   What's the Control-D business with PostScript files?
                          •   How to make use of Level 2 without a Level 2 savvy driver
                          •   How to create hypertext features in PDF files automatically
                          •   How to use PDF files without Acrobat software
                          •   Linking PDF files to the World Wide Web
                          •   Performance optimization and prepress issues
                          Contents
                          Basics – Between Monitor and Printer – Encapsulated PostScript (EPS) – PostScript Fonts – PostScript Level 2
                          – Gray Levels and Color – Display PostScript – Adobe Acrobat and PDF – Miscellaneous – Software on the
                          CD-ROM – Ghostscript Manual – Character Sets
                          PostScript & Acrobat/PDF
                          Applications, Troubleshooting, and Cross-Platform Publishing
                          By Thomas Merz. Including CD-ROM for MS-DOS/Windows/Macintosh/Unix
                          ISBN 3-540-60854-0, Springer-Verlag, Heidelberg, Berlin, New York
                          Springer-Verlag New York Inc., 175 Fifth Avenue, New York, NY 10010, U.S.A. Email: orders@springer.de
                          German Edition: Die PostScript- und Acrobat-Bibel
                          Was Sie schon immer über PostScript und Acrobat/PDF wissen wollten
                          Von Thomas Merz. 444 Seiten zweifarbig, 137 Abbildungen, Hardcover; DM 89,-
                          CD-ROM für MS-DOS/Windows/Macintosh/Unix beiliegend
                          ISBN 3-9804943-0-6, Thomas Merz Verlag, München, Fax +49/89/29 16 46 86
Ghostscript User Manual                                                       Chapter 6: More Ghostscript Applications   26