| How to use Ghostscript |
|---|
- Invoking Ghostscript
- Security Issues
- Input from a pipe
- Selecting an output device
- How Ghostscript finds files
- Summary of environment variables
- Using Ghostscript with PDF files
- Notes on specific platforms
- Switches
- Improving performance
- Debugging
- Appendix: Paper sizes known to Ghostscript
- Appendix: X default font mappings
For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install 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.
You can get a brief help message by invoking Ghostscript with the -h or -? switch, like this:
gs -h
gs -?
(Of course, for "gs" use the right command for your system.) The message shows for this executable
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 GNU/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.
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
{some program producing PS} | gs {...options...} -
{some program producing PS} | gs {...options...} -_
These switches differ from a named file in two respects:
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.
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 -h help 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 Aladdin's own drivers) 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
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
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 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
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
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=\|lpror, 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.
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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcx
Here, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bbox
It prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158
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
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:
-sPAPERSIZE=a4
-sPAPERSIZE=legal
-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.
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
% Optionally choose a default paper size other than U.S. letter.
(a4)
For a4 you can substitute any paper size Ghostscript knows.
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:
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.
Ghostscript uses a completely different rule for looking for files containing PostScript Level 2 "resources": per the Adobe documentation, it concatenates together
To look up fonts, after exhausting the search method described in the next section, it concatenates together
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.
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_DEFAULT as 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.
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 "*"):
Suggested GS_FONTPATH for different systems
System type GS_FONTPATH
Digital Unix /usr/lib/X11/fonts/Type1Adobe Ultrix /usr/lib/DPS/outline/decwin HP-UX 9 /usr/lib/X11/fonts/type1.st/typefaces IBM AIX /usr/lpp/DPS/fonts/outlines
/usr/lpp/X11/lib/X11/fonts/Type1
/usr/lpp/X11/lib/X11/fonts/Type1/DPSNeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base
/usr/lib/X11/fonts/Type1SunOS 4.x
(NeWSprint only)newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/
small_openwin/lib/fonts** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE]
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.xyzOutput 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=\|lpror, 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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcxHere, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
Bounding box output
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bboxIt prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158Currently, 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 -g500000x500000Choosing 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=hIndividual 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
% Optionally choose a default paper size other than U.S. letter.
(a4)For a4 you can substitute any paper size Ghostscript knows.
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 current directory (unless disabled by the -P- switch);
- The directories specified by -I switches in the command line, if any;
- The directories specified by the GS_LIB environment variable, if any;
- 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_DEFAULT as 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 "*"):
Suggested GS_FONTPATH for different systems
System type GS_FONTPATH
Digital Unix /usr/lib/X11/fonts/Type1Adobe Ultrix /usr/lib/DPS/outline/decwin HP-UX 9 /usr/lib/X11/fonts/type1.st/typefaces IBM AIX /usr/lpp/DPS/fonts/outlines
/usr/lpp/X11/lib/X11/fonts/Type1
/usr/lpp/X11/lib/X11/fonts/Type1/DPSNeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base
/usr/lib/X11/fonts/Type1SunOS 4.x
(NeWSprint only)newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/
small_openwin/lib/fonts** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE]
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.xyzOutput 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=\|lpror, 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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcxHere, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
Bounding box output
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bboxIt prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158Currently, 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 -g500000x500000Choosing 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=hIndividual 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
% Optionally choose a default paper size other than U.S. letter.
(a4)For a4 you can substitute any paper size Ghostscript knows.
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 current directory (unless disabled by the -P- switch);
- The directories specified by -I switches in the command line, if any;
- The directories specified by the GS_LIB environment variable, if any;
- 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_DEFAULT as 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 "*"):
Suggested GS_FONTPATH for different systems
System type GS_FONTPATH
Digital Unix /usr/lib/X11/fonts/Type1Adobe Ultrix /usr/lib/DPS/outline/decwin HP-UX 9 /usr/lib/X11/fonts/type1.st/typefaces IBM AIX /usr/lpp/DPS/fonts/outlines
/usr/lpp/X11/lib/X11/fonts/Type1
/usr/lpp/X11/lib/X11/fonts/Type1/DPSNeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base
/usr/lib/X11/fonts/Type1SunOS 4.x
(NeWSprint only)newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/
small_openwin/lib/fonts** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE]
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.xyzOutput 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=\|lpror, 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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcxHere, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
Bounding box output
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bboxIt prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158Currently, 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 -g500000x500000Choosing 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=hIndividual 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
% Optionally choose a default paper size other than U.S. letter.
(a4)For a4 you can substitute any paper size Ghostscript knows.
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 current directory (unless disabled by the -P- switch);
- The directories specified by -I switches in the command line, if any;
- The directories specified by the GS_LIB environment variable, if any;
- 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_DEFAULT as 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 "*"):
Suggested GS_FONTPATH for different systems
System type GS_FONTPATH
Digital Unix /usr/lib/X11/fonts/Type1Adobe Ultrix /usr/lib/DPS/outline/decwin HP-UX 9 /usr/lib/X11/fonts/type1.st/typefaces IBM AIX /usr/lpp/DPS/fonts/outlines
/usr/lpp/X11/lib/X11/fonts/Type1
/usr/lpp/X11/lib/X11/fonts/Type1/DPSNeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base
/usr/lib/X11/fonts/Type1SunOS 4.x
(NeWSprint only)newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/
small_openwin/lib/fonts** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE]
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.xyzOutput 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=\|lpror, 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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcxHere, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
Bounding box output
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bboxIt prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158Currently, 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 -g500000x500000Choosing 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=hIndividual 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
% Optionally choose a default paper size other than U.S. letter.
(a4)For a4 you can substitute any paper size Ghostscript knows.
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 current directory (unless disabled by the -P- switch);
- The directories specified by -I switches in the command line, if any;
- The directories specified by the GS_LIB environment variable, if any;
- 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_DEFAULT as 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 "*"):
Suggested GS_FONTPATH for different systems
System type GS_FONTPATH
Digital Unix /usr/lib/X11/fonts/Type1Adobe Ultrix /usr/lib/DPS/outline/decwin HP-UX 9 /usr/lib/X11/fonts/type1.st/typefaces IBM AIX /usr/lpp/DPS/fonts/outlines
/usr/lpp/X11/lib/X11/fonts/Type1
/usr/lpp/X11/lib/X11/fonts/Type1/DPSNeXT /NextLibrary/Fonts/outline * SGI IRIX /usr/lib/DPS/outline/base
/usr/lib/X11/fonts/Type1SunOS 4.x
(NeWSprint only)newsprint_2.5/SUNWsteNP/reloc/$BASEDIR/NeWSprint/
small_openwin/lib/fonts** SunOS 4.x /usr/openwin/lib/X11/fonts/Type1/outline ** Solaris 2.x /usr/openwin/lib/X11/fonts/Type1/outline VMS SYS$COMMON:[SYSFONT.XDPS.OUTLINE]
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.xyzOutput 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=\|lpror, 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
gs -sDEVICE=pcxmono -sOutputFile=xyz.pcxHere, as with printable files, you can use "%d" ("%%d" on DOS and MS Windows) to specify one page per output file.
Bounding box output
There is a special bbox "device" that just prints the bounding box of each page. You select it in the usual way:
gs -dNOPAUSE -dBATCH -sDEVICE=bboxIt prints the output in a format like this:
%%BoundingBox: 14 37 570 719 %%HiResBoundingBox: 14.308066 37.547999 569.495061 718.319158Currently, 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 -g500000x500000Choosing 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=hIndividual 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
% Optionally choose a default paper size other than U.S. letter.
(a4)For a4 you can substitute any paper size Ghostscript knows.
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 current directory (unless disabled by the -P- switch);
- The directories specified by -I switches in the command line, if any;
- The directories specified by the GS_LIB environment variable, if any;
- 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_DEFAULT as 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