Invoking Ghostscript

The command line to invoke Ghostscript is
essentially the same on all systems, although the name of the executable
program itself may differ among systems. For instance, to invoke
Ghostscript on Unix:

gs [switches] {filename 1} ... [switches] {filename N} ...

Ghostscript's name on different systems

System

Ghostscript's name

Unix

gs

VMS

gs

DOS & MS Windows 3

gs386

MS Windows 95/98

gswin32

MS Windows 95/98 command line

gswin32c

OS/2

gsos2

Note, though, that on a system with a windowed graphical user interface,
it's common to use Ghostscript through a previewer, so you should read the
section about previewers in the
documentation for new users.

Ghostscript is capable of interpreting PostScript, encapsulated PostScript
(EPS), DOS EPS (EPSF), and -- if the executable was built for it -- Adobe
Portable Document Format (PDF). The interpreter reads and executes the
files in sequence, using the method described under
"File searching" to find them. After doing
this, it reads further lines of PostScript language commands from the
primary input stream, normally the keyboard, interpreting each line
separately. To quit the interpreter, type "quit". The
interpreter also quits gracefully if it encounters end-of-file or
control-C.

The interpreter recognizes many switches. A switch
may appear anywhere in the command line, and applies to all files named
after it on the line. Many of the switches include "="
followed by a parameter.

Help at the command line: gs -h

You can get a brief help message by invoking Ghostscript with the
-h or -? switch, like this:

Security

Ghostscript implements a full-featured programming language, with
access to the filesystem and the ability to control a diverse set of
devices. As such, there are potential security implications.

The first line of defense is to use the security mechanisms
provided by Ghostscript. If you're running arbitrary PostScript files
(for example, those sent through email or downloaded from the Web),
make sure to use the -dSAFER option. Otherwise, you are opening up
your entire filesystem to potentially malicious code.

By default, Ghostscript opens up read access to the entire
filesystem. In general, if you're just viewing or printing documents,
this does not pose a significant security risk. However, if there is
a chance that the output of Ghostscript can leak sensitive information,
also set the -DPARANOIDSAFER option. Note, however, that this option
is incompatible with some scripts and wrappers, including gv and
related viewer apps.

We plan to make -dSAFER the default in future versions of Ghostscript.
Since most people use Ghostscript to print and view documents, rather
than to run scripts written in the PostScript language, this will
provide additional safety with little hassle for most users. If you
are using Ghostscript as a scripting language and need
unfettered access to the filesystem, use the -dNOSAFER flag to signal
explictly that you wish the PostScript code to have full access to the
file system. Currently, this flag has no effect, but it will insure
than your scripts execute as expected in future versions.

While we've tried to patch all known security problems, there is
no guarantee that we've caught them all. Ghostscript is a complex
application written in C. Buffer overflows and other exploits remain
a distinct possibility. Thus we recommend that, whenever possible,
Ghostscript should run in a secure "sandbox" environment, making
use of the security mechanisms of the underlying operating system.
In particular, we urge Linux distributors to invoke Ghostscript from
the print subsystem in a chroot'ed environment, and never as root.

We will continue to be vigilant regarding security issues. As
always, apply security updates promptly.

Input from a pipe

As noted above, one normally specifies input with file names on the command
line. However, one can also "pipe" input into Ghostscript by using the
special file name "-" or "-_", for instance

The difference between "-" and "-_" is that
"-" reads the input one character at a time, which is useful
for programs such as GSview that generate input for Ghostscript dynamically
and watch for some response, whereas "-_" reads the input in
blocks, which is more efficient for ordinary (batch) execution.

Selecting an output device

Ghostscript may be built to handle multiple output devices, and it normally
opens and directs output to the first one built in. Ghostscript's
gs -hhelp message lists
the output devices known to the executable. Once you invoke Ghostscript
you can also find out what devices are available by
"devicenames ==" at its command prompt.

A little more information about devices appears near the beginning of the
files devs.mak (for drivers that are considered "part of"
Ghostscript and are maintained by the maintainers of the main Ghostscript
code) and contrib.mak (for user-contributed drivers) used to
build Ghostscript. (If you got Ghostscript under the Aladdin Free Public License, the person or place from which
you got it is also required to make the source code available to you; if you
got it under the GNU General Public License (GPL), see the GNU General Public License for
more information.)

To use device xyz as the initial output device, use the
command-line switch

-sDEVICE=xyz

Note that this switch must precede the name of the first input file, and
only its first use has any effect. For example, for printer output in a
configuration that includes an Epson printer driver, instead of just
"gs myfile.ps" you might use

gs -sDEVICE=epson myfile.ps

Alternatively, once you invoke Ghostscript and have its own command prompt
you can type

(epson) selectdevice
(myfile.ps) run

All output then goes to the Epson printer instead of the display until you
do something to change devices. You can switch devices at any time by
using the selectdevice procedure, for
instance like one of these:

(vga) selectdevice
(epson) selectdevice

A third possibility is to define an environment variable
GS_DEVICE with the name of your desired default device.
The order of precedence for these alternatives, highest to lowest, is:

selectdevice

Highest precedence

(command line)

GS_DEVICE

(first device built in)

Default; lowest precedence

Printer resolution

Some printers can print at several different resolutions, letting you
balance resolution against printing speed. To select the resolution on
such a printer, use the -r switch:

gs -sDEVICE=printer -rXRESxYRES

For example, on Epson-compatible printers you have these choices:

gs -sDEVICE=epson

-r60x72

9-pin

lowest resolution

fastest

-r240x72

highest

slowest

-r60x60

24-pin

lowest

fastest

-r360x180

highest

slowest

Output to files

If you select a printer as the output device, Ghostscript also allows you to
control where the device sends its output. On DOS and MS Windows systems,
output normally goes directly to the printer (PRN); on Unix
or VMS systems normally to a temporary file for later printing. To send the
output to a file, use the -sOutputFile= switch (for
compatibility with older versions of Ghostscript,
-sOUTPUTFILE= also works). For instance, to direct all
output into the file ABC.xyz, use

gs -sOutputFile=ABC.xyz

The file name follows the PostScript convention that if a name begins with
%, the name must be in the form %filedevice
or %filedevice%file. The legal values of
filedevice are system-dependent, but the following have consistent meanings
across systems:

"%{filedevice}%{file}" in -sOutputFile=

filedevice

Meaning

%os%xyz

An ordinary file named xyz

%pipe%cmd

(if supported) A pipe to an instance of the command cmd

%stdout

The standard output file

Note that because of this, if you want to specify a file name that actually
begins with %, you must specify the %os%
filedevice explicitly: e.g., for output to a file named
%abc, you need to specify
-sOutputFile=%os%%abc. Note also that on DOS and MS Windows
systems, the % character has a special meaning for the
command processor (shell), so you will have to double it, e.g., for a pipe
on MS Windows,

gs -sOutputFile=%%pipe%%cmd

One page per file

You can also tell Ghostscript to put each page of output in a separate
file. To send output to a series of files each representing a single page,
use in the filename the printf format specifier
"%d" (or its extended form like "%02d");
for instance

"%{n}d" in -sOutputFile=

Output specification

Produces the series of 1-page files

-sOutputFile=ABC%d.xyz

ABC1.xyz ... ABC10.xyz ...

-sOutputFile=ABC%03d.xyz

ABC001.xyz ... ABC010.xyz ...

As noted above, on DOS and MS Windows systems, you will have to double the
% character, e.g.,

gs -sOutputFile=ABC%%03d.xyz

Output to a pipe

On Unix and (32-bit) MS Windows systems you can use this switch to send
output directly to a pipe. For example, to pipe the output to
lpr, use the command

gs -sOutputFile=\|lpr

or, as noted above,

gs -sOutputFile=%pipe%lpr

(doubling the % characters on MS Windows systems, as noted
above.) You can also send output to standard output for piping in the usual
way supported by the system:

gs -sOutputFile=- -q | ...

or, as noted above,

gs -sOutputFile=%stdout -q | ...

(again, doubling the % character on MS Windows systems.)
In this case you must also use the -q
switch to prevent Ghostscript from writing messages to standard output
which become mixed with the intended output stream.

Output to graphics file formats

File formats like PCX and PBM are also "devices". When you select a file
format as the "device", you must also specify an output file, for instance

Currently, it always prints the bounding box on stderr;
eventually, it should also recognize -sOutputFile=.

Note that this device, like other devices, has a resolution and a (maximum)
page size. As for other devices, the product (resolution x page size) is
limited to approximately 500K pixels. By default, the resolution is 4000
DPI and the maximum page size is approximately 125", or approximately 9000
default (1/72") user coordinate units. If you need to measure larger pages
than this, you must reset both the resolution and the page size in
pixels, e.g.,

gs -dNOPAUSE -dBATCH -sDEVICE=bbox -r100 -g500000x500000

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its
default page size. There are two ways to select other paper sizes from the
command line:

If the desired paper size is listed in the section on paper sizes known to Ghostscript below, you
can select it as the default paper size for a single invocation of
Ghostscript by using the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
-sPAPERSIZE=legal

Otherwise, let w be the desired paper width and h be the
desired paper height, in 1/72" units. You can set the page size using the
pair of switches

-dDEVICEWIDTHPOINTS=w-dDEVICEHEIGHTPOINTS=h

Individual documents can (and often do) specify a paper size, which takes
precedence over the default size. To force a specific paper size and
ignore the paper size specified in the document, select a paper size as
just described, and also include the
-dFIXEDMEDIA switch on the
command line.

Changing the installed default paper size

You can change the installed default paper size in installing Ghostscript
or later, by editing the initialization file gs_init.ps.
Find the consecutive lines

% Optionally choose a default paper size other than U.S. letter.
% (a4)

Then to make A4 the default paper size, uncomment the second line to change
this to

How Ghostscript finds files

When looking for initialization files (gs_*.ps,
pdf_*.ps), font files, the Fontmap file,
and files named on the command line, Ghostscript first tests whether the
file name specifies an explicit directory.

Testing a file name for an explicit directory

System

Does the name ...

Unix

Begin with /, ./ or ../ ?

DOS or MS Windows

Have : as its second character, or
begin with /, \,
./, ../, .\, or ..\ ?

VMS

Contain a node, device, root, or directory specification?

If the test succeeds, the file name
specifies an explicit directory and Ghostscript tries to open the file
using the name given. Otherwise it tries directories in this order:

The directories specified by the
GS_LIB_DEFAULT macro (if any) in the makefile
when this executable was built.

GS_LIB_DEFAULT,
GS_LIB, and the
-I parameter may specify either a single
directory or a list of directories separated by a character appropriate for
the operating system (":" on Unix systems,
"," on VMS systems, and
";" on DOS systems). We think that trying
the current directory first is a very bad idea -- it opens serious security
loopholes and can lead to very confusing errors if one has more than one
version of Ghostscript in one's environment -- but when we attempted to
change it, users insisted that we change it back. You can disable looking
in the current directory first by using the
-P- switch.

Note that Ghostscript does not use this file searching algorithm for the
run or file
operators: for these operators, it simply opens the file with the name
given. To run a file using the searching algorithm, use
runlibfile instead of
run.

Finding PostScript Level 2 resources

Ghostscript uses a completely different rule for looking for files
containing PostScript Level 2 "resources": per the Adobe documentation, it
concatenates together

the value of the system parameter
GenericResourceDir (initially
/Resource/)

the name of the resource category (for instance, ProcSet)

the value of the system parameter
GenericResourcePathSep (initially
"/")

the name of the resource instance (for instance, CIDInit)

To look up fonts, after exhausting the search method described in the
next section, it concatenates together

the value of the system parameter
FontResourceDir (initially
/Resource/Font/)

the name of the resource font (for instance, Times-Roman)

Note that even though the system parameters are named "somethingDir", they
are not just plain directory names: they have "/" on the
end, so that they can be concatenated with the category name or font name.

Font lookup

Ghostscript has a slightly different way to find the file containing a font
with a given name. This rule uses not only the search path defined by
-I, GS_LIB, and
GS_LIB_DEFAULTas described
above, but also the directory that is the value of the
FontResourceDir system parameter, and an additional list of
directories that is the value of the GS_FONTPATH environment
variable (or the value provided with the -sFONTPATH= switch,
if present).

At startup time, Ghostscript reads in the Fontmap files in
every directory on the search path (or in the list provided with the
-sFONTMAP= switch, if present): these files are catalogs of
fonts and the files that contain them. (See the
documentation of fonts for details.) Then, when Ghostscript needs to
find a font that isn't already loaded into memory, it goes through a series
of steps.

First, it looks up the font name in the combined Fontmaps. If there is an
entry for the desired font name, and the file named in the entry can be
found in some directory on the general search path (defined by
-I, GS_LIB, and
GS_LIB_DEFAULT), and the file is loaded successfully, and
loading it defines a font of the desired name, that is the end of the
process.

If this process fails at any step, Ghostscript looks for a file whose name
is the concatenation of the value of the FontResourceDir
system parameter and the font name, with no extension. If such a file
exists, can be loaded, and defines a font of the desired name, that again is
the end. The value of FontResourceDir is normally the
string /Resource/Font/, but it can be changed with the
setsystemparams operator: see the PostScript Language
Reference Manual for details.

If that fails, Ghostscript then looks for a file on the general search path
whose name is the desired font name, with no extension. If such a file
exists, can be loaded, and defines a font of the desired name, that again is
the end.

If that too fails, Ghostscript looks at the GS_FONTPATH
environment variable (or the value provided with the
-sFONTPATH= switch, if present), which is also a list of
directories. It goes to the first directory on the list, looking for all
files that appear to contain PostScript fonts; it then adds all those files
and fonts to the combined Fontmaps, and starts over.

If scanning the first FONTPATH directory doesn't produce a file that
provides the desired font, it adds the next directory on the FONTPATH list,
and so on until either the font is defined successfully or the list is
exhausted.

Finally, if all else fails, it will try to find a substitute for the font
from among the standard 35 fonts.

Differences between search path and font path

Search path

Font path

-I switch

-sFONTPATH= switch

GS_LIB and GS_LIB_DEFAULT
environment variables

GS_FONTPATH environment variable

Consulted first

Consulted only if search path and
FontResourceDir don't provide the file.

Font-name-to-file-name mapping given in Fontmap
files; aliases are possible, and there need not be any relation
between the font name in the Fontmap and the
FontName in the file.

Font-name-to-file-name mapping is
implicit -- the FontName in the file is
used. Aliases are not possible.

Only fonts and files named in Fontmap are used.

Every Type 1 font file in each directory is
available; if TrueType fonts are supported (the
ttfont.dev feature was included when the
executable was built), they are also available.

If you are using one of the following types of computer, you may wish to
set the environment variable GS_FONTPATH to
the value indicated so that Ghostscript will automatically acquire all the
installed Type 1 (and, if supported, TrueType) fonts (but see below for
notes on systems marked with "*"):

* On SGI IRIX systems, you must use Fontmap.SGI in
place of Fontmap or Fontmap.GS, because
otherwise the entries in Fontmap will take precedence over
the fonts in the FONTPATH directories.

** On Solaris systems simply setting GS_FONTPATH or
using -sFONTPATH= may not work, because for some reason some
versions of Ghostscript can't seem to find any of the Type1 fonts in
/usr/openwin/lib/X11/fonts/Type1/outline. (It says: "15
files, 15 scanned, 0 new fonts". We think this problem has been fixed in
Ghostscript version 6.0, but we aren't sure because we've never been able to
reproduce it.) See Fontmap.Sol instead. Also, on Solaris
2.x it's probably not worth your while to add Sun's fonts to your font path
and Fontmap. The fonts Sun distributes on Solaris 2.x in the directories

are already represented among the ones distributed as part of Ghostscript;
and on some test files, Sun's fonts have been shown to cause incorrect
displays with Ghostscript.

These paths may not be exactly right for your installation; if the indicated
directory doesn't contain files whose names are familiar font names like
Courier and Helvetica, you may wish to ask your system administrator where
to find these fonts.

Adobe Acrobat comes with a set of fourteen Type 1 fonts, on Unix typically
in a directory called .../Acrobat3/Fonts. There is no
particular reason to use these instead of the corresponding fonts in the
Ghostscript distribution (which are of just as good quality), except to save
about a megabyte of disk space, but the installation documentation explains
how to do it on Unix and on DOS (where you can also use
Adobe Type Manager fonts).

Temporary files

Where Ghostscript puts temporary files

Platform

Filename

Location

DOS and OpenVMS

_temp_XX.XXX

Current directory

OS/2

gsXXXXXX

Current directory

Unix

gs_XXXXX

/tmp

You can change in which directory Ghostscript creates temporary files by
setting the TMPDIR or TEMP environment
variable to the name of the directory you want used. Ghostscript currently
doesn't do a very good job of deleting temporary files if it exits because
of an error; you may have to delete them manually from time to time.

GS, GSC (MS Windows only)

Specify the names of the Ghostscript executables. GS
brings up a new typein window and possibly a graphics window;
GSC uses the DOS console. If these are not set,
GS defaults to gswin32, and
GSC defaults to gswin32c.

Defines a list of command-line arguments to be processed before the
ones actually specified on the command line. For example, setting
GS_DEVICE to XYZ is equivalent to setting
GS_OPTIONS to -sDEVICE=XYZ. The contents
of GS_OPTIONS are not limited to switches; they may include
actual file names or even "@file" arguments.

Defines a directory name for temporary files. If both
TEMP and TMPDIR are defined,
TMPDIR takes precedence.

CID font substitution

CID fonts are PostScript resources containing
large number of glyphs (e.g. glyphs for Far East languages).
Please refer Postscript Language Reference,
third edition, for details.

CID font resources are different kind of PostScript resources than fonts.
Particularly they cannot be used as regular fonts. For doing this,
CID font resourse first to be combined with a CMap resource, which
defines specific codes for hieroglyphs (this allows to use
same collection of hieroglyphs with different encodings).

The simplest method to request a font composed of CID font resource and CMap resource
is to code

/CIDFont-CMap findfont

in a PostScript document, where CIDFont is a name of any
CID font resourse, and CMap is a name of a CMap resource,
being designed for same character collection. The interpreter will compose
the font automatically from the specified CID font and CMap resources.
Another method is based on the operator composefont.

For substituting CID font resources Ghostscript 6.53 and 7.0x provides
the control file "CIDFnmap", which defines a CID font resource map.
please refer
"About CIDFnmap of Ghostscript"
in CJK.htm. However, "CIDFnmap" will be replaced by "cidfmap" in
Ghostscript 7.2x and later releases.

Using Ghostscript with PDF files

Ghostscript is normally built (except on 16-bit DOS platforms) to interpret
both PostScript and PDF files, examining each file to determine
automatically whether its contents are PDF or PostScript. All the normal
switches and procedures for interpreting PostScript files also apply to PDF
files, with a few exceptions. In addition, the
pdf2ps utility uses Ghostscript to convert
PDF to (Level 2) PostScript.

PDF files from standard input

Using the "-" or "-_"
switch you can provide PDF input from a file, but not from a pipe,
because the PDF language, unlike the PostScript language, inherently
requires random access to the file, while a pipe is always sequential. That
is,

gs -_ < somefile.pdf

(is permissible)

{some program producing PDF} | gs -_

(is not permissible)

Switches for PDF files

-dFirstPage=pagenumber

Begins interpreting on the designated page of the document.

-dLastPage=pagenumber

Stops interpreting after the designated page of the document.

-dPrinted

-dPrinted=false

Determines whether the file should be displayed or printed using the
"screen" or "printer" options for annotations and images. With
-dPrinted, the output will use the file's "print"
options; with -dPrinted=false, the output will use the
file's "screen" options. If neither of these is specified, the output will
use the screen options for any output device that doesn't have an
OutputFile parameter, and the printer options for
devices that do have this parameter.

-sPDFPassword=password

Sets the user or owner password to be used in decoding encrypted
PDF files.

Problems interpreting a PDF file

Occasionally you may try to read or print a *.pdf file that
Ghostscript doesn't recognize as PDF, even though the same file
can be opened and interpreted by an Adobe Acrobat viewer.
This can happen when, for instance, a PDF file produced on a Macintosh is
carelessly moved to another kind of system, leaving now-useless
Macintosh-specific data before the standard header. Ghostscript can't read
these files because they don't conform to the PDF standard, Adobe's Portable
Document Format Reference Manual, version 1.2, which states:

The first line of a PDF file specifies the version number of the PDF
specification to which the file adheres.... [T]he first line of a
1.2-conforming PDF file should be %PDF-1.2.

However, in an appendix the manual also says that Adobe

Acrobat viewers are very liberal in their check for a valid PDF header.
All viewers allow the header to appear anywhere in the first 1,000 bytes of
the file.

Ghostscript doesn't do this: it expects PDF files to conform to the
standard, because that's how it recognizes them among other formats it
handles, unlike Acrobat viewers which need deal only with PDF and can
therefore afford to be more liberal with PDF. So if you encounter a file
with useless characters before the header and you want to use it with
Ghostscript, you can fix it by stripping the extra characters from before
the standard header. The file should begin with exactly the characters

%PDF

PDF files are binary, not text, so be careful to edit the file as a binary,
not as text. On Unix, after determining the length of the useless prefix
string, which you can do with od, you can use
tail to strip them off. For instance:

On PCs and other systems you can use the hexl program
distributed with GNU emacs to convert the PDF file to editable text form.
After editing, hexl can convert the text form back to
binary.

Notes on specific platforms

Unix

The Ghostscript distribution includes some Unix shell scripts to use with
Ghostscript in different environments. These are all user-contributed
code, so if you have questions, please contact the user identified in the
file, not Aladdin Enterprises or artofcode LLC.

pv.sh

Preview a specified page of a dvi file in an X window

sysvlp.sh

System V 3.2 lp interface for parallel printer

pj-gs.sh

Printing on an H-P PaintJet under HP-UX

unix-lpr.sh

Queue filter for lpr under Unix;
its documentation is intended for system
administrators

lprsetup.sh

Setup for unix-lpr.sh

VMS

To be able to specify switches and file names when invoking the
interpreter, define gs as a foreign command:

$ gs == "$disk:[directory]gs.exe"

where the "disk" and "directory" specify where
the Ghostscript executable is located. For instance,

$ gs == "$dua1:[ghostscript]gs.exe"

On VMS systems, the last character of each "directory" name indicates
what sort of entity the "directory" refers to. If the "directory" name
ends with a colon ":", it is taken to refer to a logical
device, for instance

If the "directory" name ends with a closing square bracket
"]", it is taken to refer to a real directory, for instance

$ define gs_lib dua1:[ghostscript]

Defining the logical GS_LIB

$ define gs_libdisk:[directory]

allows Ghostscript to find its initialization files in the Ghostscript
directory even if that's not where the executable resides.

Although VMS DCL itself converts unquoted parameters to upper case, C
programs such as Ghostscript receive their parameters through the C runtime
library, which forces all unquoted command-line parameters to lower case.
That is, with the command

$ gs -Isys$login:

Ghostscript sees the switch as -isys$login,
which doesn't work. To preserve the case of switches, quote them like
this:

$ gs "-Isys$login:"

If you write printer output to a file with
-sOutputFile= and then want to print the file later, use
"PRINT/PASSALL".

PDF files (or PostScript files that use the
setfileposition operator) must be "stream LF" type files to
work properly on VMS systems. (Note: This definitely matters
if Ghostscript was compiled with DEC C; we are not sure of the situation if
you use gcc.) Because of this, if you transfer files by
FTP, you probably need to do one of these two things after the transfer:

Using X Windows on VMS

If you are using on an X Windows display, you can set it up with the node
name and network transport, for instance

$ set display/create/node="doof.city.com"/transport=tcpip

and then run Ghostscript by typing gs at the command line.

MS Windows

You must add gs\bin and
gs\lib to the PATH, where
gs is the top-level Ghostscript directory.

When passing options to ghostcript through a batch file wrapper such as
ps2pdf.bat you need to substitute '#' for '=' as the separator
between options and their arguments. For example:

ps2pdf -sPAPERSIZE#a4 file.ps file.pdf

Ghostscript treats '#' the same internally, and the '=' is mangled by
the command shell.

MS-DOS

Note: Ghostscript is no longer supported on MS-DOS. This
documentation is included for historical interest only.

You must add gs\bin and
gs\lib to the PATH, where
gs is the top-level Ghostscript directory.

Ghostscript supports many SuperVGA displays directly, most of them with
more than 16 colors. The complete list is in the file
devs.mak, part of Ghostscript's
source code.

Some applications, such as Microsoft Word, require a prologue in front of
the PostScript files they produce. In the case of MS Word, this prologue
is one of the *.ini files Microsoft includes with Word. Other applications
may require other prologues. You may specify a prologue on the Ghostscript
command line, for instance

gs386 prologue.ini myfile.ps

If you have a SuperVGA display that supports a 16-color mode with 800x600
pixels and you know the display mode number for this mode, you can select
it by using the command line switches

-sDEVICE=svga16 -dDisplayMode=NNN

where NNN is the display mode number in decimal. Here are modes
for some popular display chipsets; the ones that use the default value are
marked "*". If your card's chipset doesn't appear on this list, or if you
try the value here and it doesn't work, please send the name of the chipset
and its correct display mode to <bug-gs@aladdin.com> to include in
future releases.

Display modes for PC display chipsets

Chipset

Decimal

Hex

Acumos AVGA2, AVGA3

88

0x58

Advance Logic AL2101

43

0x2B

Ahead V5000

113

0x71

ATI VGAWONDER, Graphics Ultra etc.

84

0x54

Chips and Technologies

106

0x6A

Cirrus Logic CL-GD 500/600

100

0x64

Cirrus Logic GD 5422

88

0x58

Compaq VGA

89

0x59

CTI

106

0x6A

*

Genoa 5xxx, Sigma VGA

41

0x29

Genoa 6xxx

106

0x6A

MXIC MX 68010

85

0x55

NCR 77C22

88

0x58

OAK Technologies OTI-067, OTI-077, OTI037C

82

0x52

OAK Technologies OTI037C w/ NEL BIOS

91

0x5B

*

Orchid Prodesigner

41

0x29

Paradise

88

0x58

Poach

106

0x6A

Primus

42

0x2A

Realtek RT 3106

31

0x1F

Tecmar

22

0x16

Trident 8900

91

0x5B

*

Tseng ET-3000, ET-4000

41

0x29

*

VEGA

41

0x29

Video 7 SVGA

98

0x62

WD90C11

92

0x5C

Western Digital

88

0x58

Note that when passing arguments to batch files (as above) and also with the
DOS executable gs386.exe build with the Watcom C/C++ compiler,
you must use '#' rather than '=' between a
command line switch and its argument, because of a strange design decision
in the Wacom run-time library.

X Windows

Ghostscript looks for the following resources under the program name
ghostscript and class name
Ghostscript; the ones marked "**" are
calculated from display metrics:

X resources

To set X resources, put them in a file (such as
~/.Xdefaults on Unix) in a form like this:

Ghostscript*geometry:

595x842-0+0

Ghostscript*xResolution:

72

Ghostscript*yResolution:

72

Then merge these resources into the X server's resource database:

xrdb -merge ~/.Xdefaults

Ghostscript doesn't look at the default system background and foreground
colors; if you want to change the background or foreground color, you must
set them explicitly for Ghostscript. This is a deliberate choice, so that
PostScript documents will display correctly by default -- with white as
white and black as black -- even if text windows use other colors.

The geometry resource affects only window placement.

Resolution is expressed in pixels per inch (1 inch = 2.54cm).

The font tolerance gives the largest acceptable difference in height of the
screen font, expressed as a percentage of the height of the desired font.

The palette resource can be used to restrict Ghostscript to
using a grayscale or monochrome palette.

maxRGBRamp and
maxGrayRamp control the maximum number of
colors that ghostscript allocates ahead of time for the dither cube (ramp).
Ghostscript never preallocates more than half the cells in a colormap.
maxDynamicColors controls the maximum
number of colors that Ghostscript will allocate dynamically in the
colormap.

Working around bugs in X servers

The "use..." resources exist primarily to work around bugs
in X servers.

Old versions of DEC's X server (DECwindows) have bugs that
require setting useXPutImage or
useXSetTile to
false.

Some servers do not implement backing pixmaps properly, or do not
have enough memory for them. If you get strange behavior or "out
of memory" messages, try setting
useBackingPixmap to
false.

Some servers do not implement tiling properly. This appears
as broad bands of color where dither patterns should appear. If
this happens, try setting
useXSetTile to
false.

Some servers do not implement bitmap or pixmap displaying properly.
This may appear as white or black rectangles where characters
should appear; or characters may appear in "inverse video" (for
instance, white on a black rectangle rather than black on white).
If this happens, try setting
useXPutImage to
false.

X fonts

To use native X11 fonts, Ghostscript must map PostScript font names to the
XLFD font names. The resources regularFonts
(fonts available in standard or ISO-Latin-1 encoding),
symbolFonts (using Symbol encoding), and
dingbatFonts (using Dingbat encoding) give
the name mapping for different encodings. The XLFD font name in the
mapping must contain 7 dashes; the X driver adds the additional size and
encoding fields to bring the total number of dashes in the font name to 14.
See the appendix "X default font mappings"
for the full list of default mappings.

Users who switch regularly between different X servers may wish to use the
"*" wild card in place of the foundry name
(itc,
monotype,
linotype,
b&h, or
adobe); users who do not switch X servers
should leave the explicit foundry in the name, since it speeds up access to
fonts.

Ghostscript takes advantage of the "HP XLFD Enhancements," if available, to
use native X11 fonts for fonts that are anamorphically scaled, rotated, or
mirrored. If the changes have been installed to the X or font server, they
are automatically used when appropriate.

Using Ghostscript fonts on X displays

Font files distributed with Ghostscript can be used on X Windows displays.
You can find full instructions in the
documentation on fonts.

X device parameters

In addition to the device parameters recognized by all devices, Ghostscript's X
driver provides parameters to adjust its performance. Users will rarely
need to modify these. Note that these are parameters to be set with the
-d switch in the command line (e.g.,
-dMaxBitmap=10000000), not resources to be defined in the
~/.Xdefaults file.

AlwaysUpdate <boolean>

If true, the driver updates the screen after each
primitive drawing operation; if false (the default), the
driver uses an intelligent buffered updating algorithm.

MaxBitmap <integer>

If the amount of memory required to hold the pixmap for the window is no
more than the value of MaxBitmap, the driver will draw to a
pixmap in Ghostscript's address space (called a "client-side pixmap") and
will copy it to the screen from time to time; if the amount of memory
required for the pixmap exceeds the value of MaxBitmap, the
driver will draw to a server pixmap. Using a client-side pixmap usually
provides better performance -- for bitmap images, possibly much better
performance -- but since it may require quite a lot of RAM (e.g., about 2.2
Mb for a 24-bit 1024x768 window), the default value of
MaxBitmap is 0.

These control various aspects of the driver's buffering behavior. For
details, please consult the source file gdevx.h.

SCO Unix

Because of bugs in the SCO Unix kernel, Ghostscript will not work if you
select direct screen output and also allow it to write messages on the
console. If you are using direct screen output, redirect Ghostscript's
terminal output to a file.

Switches

Unless otherwise noted, these switches can be used on all platforms.

General switches

Input control

@filename

Causes Ghostscript to read filename and treat its contents the
same as the command line. (This is intended primarily for getting around
DOS's 128-character limit on the length of a command line.) Switches or
file names in the file may be separated by any amount of white space
(space, tab, line break); there is no limit on the size of the file.

--filename arg1 ...-+filename arg1 ...

Takes the next argument as a file name as usual, but takes all
remaining arguments (even if they have the syntactic form of switches) and
defines the name ARGUMENTS in userdict (not systemdict) as
an array of those strings, before running the file. When
Ghostscript finishes executing the file, it exits back to the shell.

-@filename arg1 ...

Does the same thing as -- and -+, but
expands @filename arguments.

--_

These are not really switches: they tell Ghostscript to read from
standard input, which is coming from a file or a pipe,
with or without buffering.
See "Input from a pipe" above.

-ctokens ...

Interprets arguments as PostScript code up to the next argument that
begins with "-" followed by a non-digit, or with
"@". For example, if the file quit.ps
contains just the word "quit", then
-c quit on the command line is equivalent to
quit.ps there. Each argument must be exactly one token, as
defined by the token operator.

-f

Interprets following non-switch arguments as file names to be executed
using the normal run command. Since this is the default
behavior, -f is useful only for terminating the list of
tokens for the -c switch.

-ffilename

Execute the given file, even if its name begins with a
"-" or "@".

File searching

Note that by "library files" here we mean all the files identified using
the search rule under "How Ghostscript finds
files" above: Ghostscript's own initialization files, fonts, and files
named on the command line.

-Idirectories

Adds the designated list of directories at the head of the search path
for library files.

-P

Makes Ghostscript look first in the current directory for library
files. This is currently the default.

-P-

Makes Ghostscript not look first in the current
directory for library files (unless, of course, the first explicitly
supplied directory is ".").

Setting parameters

-Dname-dname

Define a name in systemdict with value=true.

-Dname=token-dname=token

Define a name in systemdict with the given definition. The token must
be exactly one token (as defined by the token operator) and
must not contain any whitespace. If the token is a non-literal name, it
must be true, false, or null.

-Sname=string-sname=string

Define a name in systemdict with a given string as value. This is
different from -d. For example, -dXYZ=35
on the command line is equivalent to the program fragment

/XYZ 35 def

whereas -sXYZ=35 is equivalent to

/XYZ (35) def

-uname

Un-define a name, cancelling -d or -s.

Note that the initialization file gs_init.ps makes
systemdict read-only, so the values of names defined with
-D, -d, -S, and
-s cannot be changed -- although, of course, they can be
superseded by definitions in userdict or other dictionaries.
However, device parameters set this way (PageSize,
Margins, etc.) are not read-only, and can
be changed by code in PostScript files.

-gnumber1xnumber2

Equivalent to -dDEVICEWIDTH=number1 and
-dDEVICEHEIGHT=number2, specifying the device
width and height in pixels for the benefit of devices such as X11 windows
and VESA displays that require (or allow) you to specify width and height.
Note that this causes documents of other sizes to be clipped, not scaled:
see -dFIXEDMEDIA below.

-rnumber (same
as -rnumberxnumber)
-rnumber1xnumber2

Equivalent to -dDEVICEXRESOLUTION=number1 and
-dDEVICEYRESOLUTION=number2, specifying the device
horizontal and vertical resolution in pixels per inch for the benefit of
devices such as printers that support multiple X and Y resolutions.

Suppress messages

-q

Quiet startup: suppress normal startup messages, and also do the
equivalent of -dQUIET.

Parameter switches (-d and -s)

As noted above, -d and -s define initial
values for PostScript names. Some of these names are parameters that
control the interpreter or the graphics engine. You can also use
-d or -s to define a value for any device
parameter of the initial device (the one defined with
-sDEVICE=, or the default device if this switch is not
used). For example, since the ppmraw device has a numeric
GrayValues parameter that controls the number of bits per
component, -sDEVICE=ppmraw -dGrayValues=16 will make this
the default device and set the number of bits per component to 4 (log2(16)).

Rendering parameters

-dCOLORSCREEN
-dCOLORSCREEN=0
-dCOLORSCREEN=false

On high-resolution devices (at least 150 dpi resolution, or
-dDITHERPPI specified), -dCOLORSCREEN
forces the use of separate halftone screens with different angles for CMYK
or RGB if halftones are needed (this produces the best-quality output);
-dCOLORSCREEN=0 uses separate screens with the same
frequency and angle; -dCOLORSCREEN=false forces the use of
a single binary screen. The default if COLORSCREEN is not
specified is to use separate screens with different angles if the device
has fewer than 5 bits per color, and a single binary screen (which is never
actually used under normal circumstances) on all other devices.

-dDITHERPPI=lpi

Forces all devices to be considered high-resolution, and forces use of
a halftone screen or screens with lpi lines per inch, disregarding
the actual device resolution. Reasonable values for lpi are
N/5 to N/20, where N is the
resolution in dots per inch.

-dDOINTERPOLATE

Turns on image interpolation for all images, improving image quality for
scaled images at the expense of speed. Note that
-dNOINTERPOLATE overrides -dDOINTERPOLATE if
both are specified.

-dNOCIE

Substitutes DeviceGray and DeviceRGB
for CIEBasedA and CIEBasedABC color spaces respectively. Useful only on
very slow systems where color accuracy is less important.

Page parameters

-dFIXEDMEDIA

Causes the media size to be fixed after initialization, forcing pages
of other sizes or orientations to be clipped. This may be useful when
printing documents on a printer that can handle their requested paper size
but whose default is some other size. Note that -g
automatically sets -dFIXEDMEDIA, but
-sPAPERSIZE= does not.

Defines the meaning of the 0 and 1 orientation values for the
setpage[params] compatibility operators. The default value of
ORIENT1 is true (set in gs_init.ps), which
is the correct value for most files that use setpage[params] at all,
namely, files produced by badly designed applications that "know" that the
output will be printed on certain roll-media printers: these applications
use 0 to mean landscape and 1 to mean portrait.
-dORIENT1=false declares that 0 means portrait and 1 means
landscape, which is the convention used by a smaller number of files
produced by properly written applications.

Font-related parameters

-dDISKFONTS

Causes individual character outlines to be loaded from the disk the
first time they are encountered. (Normally Ghostscript loads all the
character outlines when it loads a font.) This may allow loading more
fonts into memory at the expense of slower rendering.
DISKFONTS is effective only if the diskfont feature was
built into the executable; otherwise it is ignored.

-dLOCALFONTS

Causes Type 1 fonts to be loaded into the current VM -- normally local
VM -- instead of always being loaded into global VM. Useful only for
compatibility with Adobe printers for loading some obsolete fonts.

-dNOCCFONTS

Suppresses the use of fonts precompiled into the Ghostscript executable.
See "Precompiling fonts" in the
documentation on fonts for details. This is probably useful only for
debugging.

-dNOFONTMAP

Suppresses the normal loading of the Fontmap file. This may be useful
in environments without a file system.

-dNOFONTPATH

Suppresses consultation of GS_FONTPATH. This may be
useful for debugging.

-dNOPLATFONTS

Disables the use of fonts supplied by the underlying platform (X
Windows or Microsoft Windows). This may be needed if the platform fonts
look undesirably different from the scalable fonts.

-sFONTMAP=filename1;filename2;...

Specifies alternate name or names for the Fontmap file. Note that the
names are separated by ":" on Unix systems, by
";" on DOS or MS Windows systems, and by
"," on VMS systems, just as for search paths.

-sFONTPATH=dir1;dir2;...

Specifies a list of directories that will be scanned when looking for
fonts not found on the search path, overriding the environment variable
GS_FONTPATH.

-sSUBSTFONT=fontname

Causes the given font to be substituted for all unknown fonts, instead
of using the normal intelligent substitution algorithm. Also, in this
case, the font returned by findfont is the actual font
named "fontname", not a copy of the font with the
FontName changed to the requested one.

Interaction-related parameters

-dBATCH

Causes Ghostscript to exit after processing all files named on the
command line, rather than going into an interactive loop reading PostScript
commands. Equivalent to putting -c quit at the end of the command line.

-dNOPAGEPROMPT

Disables only the prompt, but not the pause, at the end of each page.
This may be useful on PC displays that get confused if a program attempts
to write text to the console while the display is in a graphics mode.

-dNOPAUSE

Disables the prompt and pause at the end of each page. Normally one
should use this (along with -dBATCH) when producing output
on a printer or to a file; it also may be desirable for applications where
another program is "driving" Ghostscript.

-dNOPROMPT

Disables the prompt printed by Ghostscript when it expects interactive
input, as well as the end-of-page prompt (-dNOPAGEPROMPT);
also disables the implicit flushpage that normally occurs
each time Ghostscript asks for more input. This allows piping input
directly into Ghostscript, as long as the data doesn't refer to
currentfile.

-dQUIET

Suppresses routine information comments on standard output. This is
currently necessary when redirecting device output to standard output.

-dSHORTERRORS

Makes certain error and information messages more Adobe-compatible.

-sstdout=filename

Redirect PostScript %stdout to a file or
stderr, to avoid it being mixed with device stdout.
To redirect stdout to stderr use -sstdout=%stderr.
To cancel redirection of stdout use -sstdout=%stdout
or -sstdout=-.

-dTTYPAUSE

Causes Ghostscript to read a character from /dev/tty,
rather than standard input, at the end of each page. This may be useful if
input is coming from a pipe. Note that -dTTYPAUSE
overrides -dNOPAUSE.

Device and output selection parameters

-dNODISPLAY

Initializes Ghostscript with a null device (a device that discards the
output image) rather than the default device or the device selected with
-sDEVICE=. This is usually useful only when running
PostScript code whose purpose is to compute something rather than to
produce an output image; for instance, when converting PostScript to PDF.

Selects an alternate output file (or pipe) for the initial output
device, as described above.

Other parameters

-dDELAYBIND

Causes bind to remember all its invocations, but not
actually execute them until the .bindnow procedure is
called. Useful only for certain specialized packages like
pstotext that redefine operators.

-dDOPDFMARKS

Causes pdfmark to be called for bookmarks,
annotations, links and cropbox when processing PDF files.
Normally, pdfmark is only called for these types
for PostScript files or when the output device requests it
(e.g. pdfwrite device).

-dNOBIND

Disables the bind operator. Useful only for debugging.

-dNOCACHE

Disables character caching. Useful only for debugging.

-dNOGC

Suppresses the initial automatic enabling of the garbage collector in
Level 2 systems. (The vmreclaim operator is not disabled.)
Useful only for debugging.

-dNOSAFER (equivalent to -dDELAYSAFER).

This flag disables SAFER mode until the .setsafe
procedure is run. This is intended for clients or scripts that cannot
operate in SAFER mode. If Ghostscript is started with -dNOSAFER
or -dDELAYSAFER, PostScript programs are allowed to read, write,
rename or delete any files in the system that are not protected by operating
system permissions.

This mode should be used with caution, and .setsafe should be
run prior to running any PostScript file with unknown contents.

-dSAFER

Disables the deletefile and renamefile
operators, and the ability to open piped commands (%pipe%cmd)
at all. Only %stdout and %stderr can be opened
for writing.

This mode also sets the .LockSafetyParams
parameter of the default device, or the device specified with the -sDEVICE=
switch to protect against programs that attempt to write to files using the
OutputFile device parameter. Note that since the device parameters specified
on the command line (including OutputFile) are set prior to SAFER mode,
the -sOutputFile=... on the command line is unrestricted.

SAFER mode also prevents changing the /GenericResourceDir,
/FontResourceDir and either the /SystemParamsPassword or the /StartJobPassword.

Note: While SAFER mode is not the default, in a subsequent release of
Ghostscript, SAFER mode will be the default thus scripts or programs that need
to open files or set restricted parameters will require the -dNOSAFER
command line option.

When running -dNOSAFER it is possible to perform a save,
followed by .setsafe, execute a file or procedure in SAFER mode,
then use restore to return to NOSAFER mode. In order to prevent
the save object from being restored by the foreign file or procedure, the
.runandhide operator should
be used to hide the save object from the restricted procedure.

-dPARANOIDSAFER

Disables reading of files other than %stdin, those given as
a command line argument, or those contained on one of the paths given by
LIBPATH and FONTPATH and specified by the system params /FontResourceDir
and /GenericResourceDir.

-dPARANOIDSAFER implies -dSAFER so if
-dPARANOIDSAFER is given on the command line,
-dSAFER is optional.

-dSTRICT

Disables as many Ghostscript extensions as feasible, to be more helpful
in debugging applications that produce output for Adobe and other RIPs.

-dWRITESYSTEMDICT

Leaves systemdict writable. This is necessary when
running special utility programs such as font2c and
pcharstr, which must bypass normal PostScript access
protection.

Improving performance

Ghostscript attempts to find an optimum balance between speed and memory
consumption, but there are some cases in which you may get a very large
speedup by telling Ghostscript to use more memory.

If you are using X Windows, setting the -dMaxBitmap=
parameter described above may
dramatically improve performance on files that have a lot of bitmap images.

If you are using Chinese, Japanese, or other fonts with very large character
sets, adding the following sequence of switches before the first file name
may dramatically improve performance at the cost of an additional 2-3 Mb of
memory: -c 3000000 setvmthreshold -f.

Debugging

The information here describing the debugging switches is probably
interesting only to developers. The -Z switch applies only
if the interpreter was built for a debugging
configuration. In the table below, the first column is a debugging
switch, the second is an equivalent switch (if any) and the third is its
usage.

Switches used in debugging

Switch

Equivalent

-A

-Z@

Fill empty storage with a distinctive bit pattern for debugging

-A-

-Z-@

Turn off -A

-Bsize

Run all subsequent files named on the command line (except for
-F) through the run_string interface, using a
buffer of size bytes

-B-

Turn off -B: run subsequent files (except for
-F) directly in the normal way

-E

-Z#

Turn on tracing of error returns from operators

-E-

-Z-#

Turn off -E

-Ffile

Execute the file with -B1 temporarily in effect

-Kn

Limit the total amount of memory that the interpreter can have
allocated at any one time to nK bytes.
n is a positive decimal integer.

-Mn

Force the interpreter's allocator to acquire additional memory
in units of nK bytes, rather than the default
(currently 20K on DOS systems, 50K on Unix). n
is a positive decimal integer, on DOS systems no greater than
63.

-Nn

Allocate space for nK names, rather than the
default (normally 64K). n may be greater than
64 only if EXTEND_NAMES was defined when the
interpreter was compiled .

-Zxxx-Z-xxx

Turn debugging printout on (off). Each of the xxx
characters selects an option. Case is significant: "a" and
"A" have different meanings.

0

garbage collector, minimal detail

1

type 1 and type 42 font interpreter

2

curve subdivider/rasterizer

3

curve subdivider/rasterizer, detail

4

garbage collector (strings)

5

garbage collector (strings, detail)

6

garbage collector (chunks, roots)

7

garbage collector (objects)

8

garbage collector (refs)

9

garbage collector (pointers)

a

allocator (large blocks only)

A

allocator (all calls)

b

bitmap image processor

B

bitmap images, detail

c

color/halftone mapper

d

dictionary put/undef

D

dictionary lookups

e

external (OS-related) calls

f

fill algorithm (summary)

F

fill algorithm (detail)

g

gsave/grestore[all]

h

halftone renderer

H

halftones, every pixel

i

interpreter, just names

I

interpreter, everything

j

(Japanese) composite fonts

k

character cache and xfonts

K

character cache, every access

l

command lists, bands

L

command lists, everything

m

makefont and font cache

n

name lookup (new names only)

o

outliner (stroke)

O

stroke detail

p

band list paths

P

all paths

q

clipping

r

arc renderer

s

streams

S

scanner

t

tiling algorithm

u

undo saver (for save/restore), finalization

U

undo saver, more detail

v

alpha/transparency

V

alpha/transparency, more detail

w

compression encoder/decoder

x

transformations

y

Type 1 hints

Y

Type 1 hints, every access

z

trapezoid fill

#

operator error returns

%

externally processed comments

*

image and RasterOp parameters

:

command list and allocator/time summary

~

math functions and Functions

'

contexts, create/destroy

"

contexts, every operation

^

reference counting

_

high-level output

|

(reserved for experimental code)

The following switch affects what is printed, but does not select specific
items for printing:

/

include file name and line number on all trace output

These switches select debugging options other than what should be printed:

$

set unused parts of object references to
identifiable garbage values

+

use minimum-size stack blocks

,

don't use path-based banding

`

don't use high-level banded images

.

use small-memory table sizes even on large-memory
machines

?

validate pointers before, during and after garbage
collection, also before and after save and restore; also make other
allocator validity checks

Appendix: Paper sizes known to Ghostscript

The paper sizes known to Ghostscript are defined at the beginning of the
initialization file gs_statd.ps; see the comments there for
more details about the definitions. The table here lists them by name and
size. gs_statd.ps defines their sizes exactly in points,
and the dimensions in inches (at 72 points per inch) and centimeters shown
in the table are derived from those, rounded to the nearest 0.1 unit. A
guide to international paper sizes can be found at

This software is provided AS-IS with no warranty, either express or
implied.
This software is distributed under license and may not be copied,
modified or distributed except as expressly authorized under the terms
of the license contained in the file LICENSE in this distribution.
For more information about licensing, please refer to
http://www.ghostscript.com/licensing/. For information on
commercial licensing, go to http://www.artifex.com/licensing/ or
contact Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.