gs – Aladdin Ghostscript (PostScript and PDF language interpreter)

gs [ options ] [ files ] ...

Ghostscript is a programming language similar to Adobe Systems' PostScript and PDF languages, which are in turn similar to Forth. Gs reads files in sequence and executes them as Ghostscript programs. After doing this, it reads further input from the standard input. If the file – is named, however, it represents the standard input, which is read in order and not after the files on the command line. Each line is interpreted separately. The `quit' command, or end–of–file, exits the interpreter.

The interpreter recognizes several switches described below, which may appear anywhere in the command line and apply to all files thereafter.

The –h or –? options give help and list the available devices; the default is plan9, which produces compressed image files suitable for viewing with page(1) (but note that page(1) will invoke gs automatically; see its manual).

Ghostscript may be built with multiple output devices. Ghostscript normally opens the first one and directs output to it. To use device xyz as the initial output device, include the switch
in the command line. This switch must precede the first PostScript file and only its first invocation has any effect. Output devices can also be selected by the word selectdevice in the input language, or by setting the environment variable GS_DEVICE. The order of precedence for these alternatives, highest to lowest, is:
(command line)

Normally, output goes directly to a scratch file. To send the output to a series of files,, etc., use the switch
The %d may be any printf (see fprintf(2)) format specification. Each file will receive one page of output. If the file name begins with a pipe character, the output will be sent as standard input to the following pipeline. For example,
Specifying the file – will send the files to standard output; this also requires enabling the –q option.

Initialization files
When looking for the initialization files (gs_*.ps), the files related to fonts, or the file for the run operator, Ghostscript first looks for the file (if it doesn't start with a slash) in the current directory, then in these directories in the following order:
1.    Any directories specified by –I switches in the command line (see below);
2.    Any directories specified by the GS_LIB environment variable;
3.    The directories /sys/lib/ghostscript, /sys/lib/ghostscript/font, and /sys/lib/postscript/font.

The GS_LIB or –I parameters may be a single directory or a colon–separated list.

–– filename arg1 ...
Take the next argument as a file name as usual, but take all remaining arguments (even if they have the syntactic form of switches) and define 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.
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 white space.
Define a name in systemdict with value=null.
Define a name in systemdict with a given string as value. This is different from –d. For example, –dname=35 is equivalent to the program fragment
/name 35 def
whereas –sname=35 is equivalent to
/name (35) def
q    Quiet startup: suppress normal startup messages, and also do the equivalent of –dQUIET.
Equivalent to –dDEVICEWIDTH=number1 and –dDEVICEHEIGHT=number2. This is for the benefit of devices, such as windows, that allow width and height to be specified.
Equivalent to –dDEVICEXRESOLUTION=number1 and –dDEVICEYRESOLUTION= number2. This is for the benefit of devices, such as printers, that support multiple X and Y resolutions. If only one number is given, it is used for both X and Y resolutions.
Adds the designated list of directories at the head of the search path for library files.

Note that makes systemdict read–only, so the values of names defined with –D/d/S/s cannot be changed (although, of course, they can be superseded by definitions in userdict or other dictionaries.)

Special names
Exit after the last file has been processed. This is equivalent to listing at the end of the list of files.
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 RAM, at the expense of slower rendering.
Disables character caching. Only useful for debugging.
Disables the `bind' operator. Only useful for debugging.
Suppresses the normal initialization of the output device. This may be useful when debugging.
Disables the prompt and pause at the end of each page. This may be desirable for applications where another program (e.g. page(1)) is `driving' Ghostscript.
Disables the deletefile and renamefile operators, and the ability to open files in any mode other than read–only. This may be desirable for spoolers or other sensitive environments. Files in the /fd directory may still be opened for writing.
Leaves systemdict writable. This is necessary when running special utility programs such as font2c and pcharstr, which must bypass normal PostScript access protection.
Selects an alternate initial output device, as described above.
Selects an alternate output file (or pipe) for the initial output device, as described above.

Startup–files, utilities, examples, and basic font definitions.
Additional font definitions.


page(1), ps2pdf(1)
The Ghostscript document files in doc and man subdirectories of the source directory.

The treatment of standard input is non–standard.