How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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. (However, with the DOS executable gs386.exe in the standard Ghostscript distribution, you must use "#" rather than "=", because of a strange design decision in the Watcom C/C++ run-time library used to build it.)

Help at the command line: gs -h

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

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 "-", for instance

{some program producing PS} | gs {...options...} -

"-" differs from a named file in two respects:

  1. When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, "-" is really only useful as the last argument on the command line.
  2. "-" can't be used to pipe PDF input to Ghostscript. See "Using Ghostscript with PDF files" below.

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 -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

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 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

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 ...

Output to a pipe

On Unix 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

You can also send output to standard output for piping in the usual way supported by the system:

gs -sOutputFile=- -q | ...

(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.pcx

Here, as with printable files, you can use "%d" to specify one page per output file.

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its default page size, but it knows about many others, listed by name and size in the section on paper sizes known to Ghostscript. To select one of these as the default paper size for a single invocation of Ghostscript, you can use the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
!-- [2.0 end contents] ---------------------------------------------------- -->

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998 ./usr/doc/gs-aladdin/Use.htm0100644000000000000000000025304507051042760014553 0ustar rootroot How to use Ghostscript

How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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. (However, with the DOS executable gs386.exe in the standard Ghostscript distribution, you must use "#" rather than "=", because of a strange design decision in the Watcom C/C++ run-time library used to build it.)

Help at the command line: gs -h

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

  • its version
  • the format of the command to invoke it
  • a few of the most useful switches
  • the formats it can interpret
  • the devices for which it can produce output
  • where it looks for font files
  • where and how to send bug reports

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 "-", for instance

{some program producing PS} | gs {...options...} -

"-" differs from a named file in two respects:

  1. When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, "-" is really only useful as the last argument on the command line.
  2. "-" can't be used to pipe PDF input to Ghostscript. See "Using Ghostscript with PDF files" below.

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 -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

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 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

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 ...

Output to a pipe

On Unix 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

You can also send output to standard output for piping in the usual way supported by the system:

gs -sOutputFile=- -q | ...

(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.pcx

Here, as with printable files, you can use "%d" to specify one page per output file.

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its default page size, but it knows about many others, listed by name and size in the section on paper sizes known to Ghostscript. To select one of these as the default paper size for a single invocation of Ghostscript, you can use the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
!-- [2.0 end contents] ---------------------------------------------------- -->

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998 ./usr/doc/gs-aladdin/Use.htm0100644000000000000000000025304507051042760014553 0ustar rootroot How to use Ghostscript

How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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. (However, with the DOS executable gs386.exe in the standard Ghostscript distribution, you must use "#" rather than "=", because of a strange design decision in the Watcom C/C++ run-time library used to build it.)

Help at the command line: gs -h

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

  • its version
  • the format of the command to invoke it
  • a few of the most useful switches
  • the formats it can interpret
  • the devices for which it can produce output
  • where it looks for font files
  • where and how to send bug reports

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 "-", for instance

{some program producing PS} | gs {...options...} -

"-" differs from a named file in two respects:

  1. When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, "-" is really only useful as the last argument on the command line.
  2. "-" can't be used to pipe PDF input to Ghostscript. See "Using Ghostscript with PDF files" below.

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 -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

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 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

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 ...

Output to a pipe

On Unix 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

You can also send output to standard output for piping in the usual way supported by the system:

gs -sOutputFile=- -q | ...

(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.pcx

Here, as with printable files, you can use "%d" to specify one page per output file.

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its default page size, but it knows about many others, listed by name and size in the section on paper sizes known to Ghostscript. To select one of these as the default paper size for a single invocation of Ghostscript, you can use the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
!-- [2.0 end contents] ---------------------------------------------------- -->

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998 ./usr/doc/gs-aladdin/Use.htm0100644000000000000000000025304507051042760014553 0ustar rootroot How to use Ghostscript

How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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. (However, with the DOS executable gs386.exe in the standard Ghostscript distribution, you must use "#" rather than "=", because of a strange design decision in the Watcom C/C++ run-time library used to build it.)

Help at the command line: gs -h

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

  • its version
  • the format of the command to invoke it
  • a few of the most useful switches
  • the formats it can interpret
  • the devices for which it can produce output
  • where it looks for font files
  • where and how to send bug reports

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 "-", for instance

{some program producing PS} | gs {...options...} -

"-" differs from a named file in two respects:

  1. When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, "-" is really only useful as the last argument on the command line.
  2. "-" can't be used to pipe PDF input to Ghostscript. See "Using Ghostscript with PDF files" below.

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 -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

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 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

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 ...

Output to a pipe

On Unix 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

You can also send output to standard output for piping in the usual way supported by the system:

gs -sOutputFile=- -q | ...

(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.pcx

Here, as with printable files, you can use "%d" to specify one page per output file.

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its default page size, but it knows about many others, listed by name and size in the section on paper sizes known to Ghostscript. To select one of these as the default paper size for a single invocation of Ghostscript, you can use the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
!-- [2.0 end contents] ---------------------------------------------------- -->

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998 ./usr/doc/gs-aladdin/Use.htm0100644000000000000000000025304507051042760014553 0ustar rootroot How to use Ghostscript

How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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. (However, with the DOS executable gs386.exe in the standard Ghostscript distribution, you must use "#" rather than "=", because of a strange design decision in the Watcom C/C++ run-time library used to build it.)

Help at the command line: gs -h

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

  • its version
  • the format of the command to invoke it
  • a few of the most useful switches
  • the formats it can interpret
  • the devices for which it can produce output
  • where it looks for font files
  • where and how to send bug reports

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 "-", for instance

{some program producing PS} | gs {...options...} -

"-" differs from a named file in two respects:

  1. When Ghostscript finishes reading from the pipe, it quits rather than going into interactive mode. Because of this, "-" is really only useful as the last argument on the command line.
  2. "-" can't be used to pipe PDF input to Ghostscript. See "Using Ghostscript with PDF files" below.

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 -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

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 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

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 ...

Output to a pipe

On Unix 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

You can also send output to standard output for piping in the usual way supported by the system:

gs -sOutputFile=- -q | ...

(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.pcx

Here, as with printable files, you can use "%d" to specify one page per output file.

Choosing paper size

Ghostscript is distributed configured to use U.S. letter paper as its default page size, but it knows about many others, listed by name and size in the section on paper sizes known to Ghostscript. To select one of these as the default paper size for a single invocation of Ghostscript, you can use the -sPAPERSIZE= switch, for instance

-sPAPERSIZE=a4
!-- [2.0 end contents] ---------------------------------------------------- -->

Copyright © 1996, 1997, 1998 Aladdin Enterprises. All rights reserved.

This file is part of Aladdin Ghostscript. See the Aladdin Free Public License (the "License") for full details of the terms of using, copying, modifying, and redistributing Aladdin Ghostscript.

Ghostscript version 5.50, 16 September 1998 ./usr/doc/gs-aladdin/Use.htm0100644000000000000000000025304507051042760014553 0ustar rootroot How to use Ghostscript

How to use Ghostscript

Table of contents

For other information, see the Ghostscript overview, the new user's documentation on previewers and, if necessary, how to install Ghostscript.


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  gswin32
MS Windows 95 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 enc