Ghostscript User Manual
Ghostscript User Manual
What is Ghostscript?
Installing Ghostscript
Ghostscript Primer
Ghostscript Reference
Fig. 2.
Configuring
Ghostscript
path names in
GSview.
pensated for by several extensions in Mac GS Viewer and its Device drivers and file output. By default, Ghostscript ren-
user interface. ders into a Macintosh window. It can also create instructions for
To install Mac GS Viewer you need the program Stuffit Ex- other devices or graphics file formats. You can copy the bit-
pander. Decompress the archive macgs-v1.0-files.sit.hqx. mapped contents of a window to the clipboard, or save it as a
This places the contents of this archive in the Ghostscript folder. PICT file with “File”, “Save As...”. In the “Devices” menu you
Decompress one of the executable files can choose the output file. Although the Ghostscript source dis-
macgs-v1.0-ppc.sit.hqx tribution contains many dozens of drivers, the Macintosh ver-
macgs-v1.0-68k.sit.hqx sion only contains the screen driver, a few printer drivers, and
macgs-v1.0-classic.sit.hqx
drivers for the file formats PCX, PBM, and TIFF. This decision
along with the Ghostscript fonts from the archive macgs-v1.0- has been made in order to reduce storage requirements. Since it
fonts.sit.hqx into the same folder. The archive macgs-v1.0- is not possible to dynamically load drivers, you have to recom-
src.sit.hqx is only needed for compiling an individual version pile Ghostscript if you want to use additional drivers.
of Ghostscript.
Font configuration on the Mac. Ghostscript uses Post-
Launching and testing Ghostscript. Launch Ghostscript Script fonts in ASCII format. Since PostScript fonts on the Mac
by double-clicking on the Mac GS Viewer icon. After initializa- are usually stored in a compact resource format, Ghostscript
tion, the console window (“Talk to Ghostscript”) will appear cannot use them directly (this is planned for a future version).
with the Ghostscript prompt However, you can convert standard Mac PostScript fonts for
GS> use with Ghostscript with the unadobe utility. Execute the fol-
Although you can type in PostScript commands in the console lowing steps for each font you want to use:
window, it’s much easier to use Mac-style menu commands. ➤ Start unadobe and open the font file. unadobe doesn’t change
The sequence “File”, “Open” lets you open EPSF or TEXT files, the font data, but instead converts the resource representa-
e.g., the test file tiger.ps in the Ghostscript folder. Activate bal- tion to a textual representation suitable for Ghostscript. Save
Selecting a driver. Usually, Ghostscript uses the first driver In this line, remove the “%” comment sign at the beginning to
in its internal list (configured at build time). This driver outputs use A4 format. You can also replace the “a4” in parentheses by
to the screen in the standard configurations on all operating any other known format. A list of all formats known to Ghost-
systems. You can select another driver on the command line: script (and their dimensions) can be found in the gs_statd.ps file.
Alternatively, you can change the page size on the Ghostscript
gs -sDEVICE=laserjet file.ps -c quit
command line:
This instructs Ghostscript to produces output for the particular
gs -sPAPERSIZE=legal file.ps
device or file format (laserjet in the example above). Using the
following commands at the Ghostscript prompt, you can
change the driver at any time: 4.2 Printing with Ghostscript
GS>(epson) selectdevice Printing on MS-DOS. The following call processes a Post-
GS>(file.ps) run Script file for output on a Laserjet 4 printer connected to the
For printers with multiple resolutions you can also set the de- parallel interface:
sired print resolution using the -r option: gs386 -q -dNOPAUSE -sDEVICE=ljet4 file.ps -c quit
gs -sDEVICE=epson -r60x72 -c quit The -c quit option is used to exit Ghostscript after the PostScript
file is completely rendered. Due to the -q option, Ghostscript it-
Redirecting printer data. On MS-DOS, Ghostscript sends
self works quietly. However, the 386 MS-DOS extender still
printer data directly to the parallel port. On Unix, the printer
presents its copyright banner. You can suppress it with an envi-
data is sent to a temporary file. You can also redirect it to your
ronment variable:
own print file:
set DOS4G=quiet
gs -sDEVICE=laserjet -sOutputFile=laserjet.prn file.ps
-c quit If your printer is not connected to the parallel interface or you
If the output file name contains the variable %d (e.g. laser%d. want to bring the printer data to another machine, you can redi-
prn), Ghostscript produces one output file per page and replac- rect it to a file:
es the %d with the page number. On Unix, you can also redirect gs386 -q -dNOPAUSE -sDEVICE=ljet4 -sOutputFile=ljet.prn
the data to a pipe using the “\|” syntax: file.ps -c quit
-Dname -
-dname Instructs Ghostscript to read standard input from file or pipe
Defines name in systemdict with a value of true. (instead of from the keyboard). Ghostscript reads and processes
data from standard input and exits. Note that it’s not possible to
read PDF files from standard input.
-dNOPLATFONTS -sFONTPATH=<dirname1>:<dirname2>...
Disables platform fonts for X Windows or Microsoft Windows Defines one or more directory names to be searched for font
(see section 2.5, »Font Configuration«). definitions. Several path names are separated by a semicolon
“;” under Windows and OS/2 and a colon “:” under Unix.
-dNOPROMPT
Disables the prompt (but not the pause) at the end of each page. -sOutputFile=<filename>
This prevents text and graphics output from being mixed on PC Selects an output file name or pipe. If the file name contains the
displays. characters “%d”, Ghostscript replaces the “%d” with the actual
page number and creates one file for each page, e.g., page%d.prn
-dORIENT1=false
yields page1.prn, page2.prn and so on.
Exchanges the meaning of the values 0 and 1 for indicating
On OS/2, Windows 95 and Windows NT you can use printer
page orientation with setpageparams. This is needed for the Post-
queue names: -sOutputFile="\\spool\printername" sends
Script code of certain applications.
the output to the named printer queue. If the printer name is
-dQUIET missing, Ghostscript prompts for the name of the (connected)
Suppress informational messages. This is necessary when redi- printer (Windows) or uses the default queue (OS/2).
recting device output to stdout. On Unix, you can also redirect the output to another pro-
gram via pipe: -sOutputFile=\|lp. The special name “-” for
-dSAFER the output file instructs Ghostscript to send the data to its stan-
Disables the PostScript operators for writing or deleting disk
dard output.
files. This is intended for using Ghostscript as viewer for a Web
browser in a secure mode. -sPAPERSIZE=<papersize>
Selects a page size, e.g., a4. The file gs_statd.ps contains a list of
-dSHORTERRORS supported page size names.
Brackets several error messages with %%[ and ]%% (as Adobe
Interpreters do). -sPSFile=<filename>
Defines the output file name for PDF to PostScript conversion.
-dTextAlphaBits=<n>
Specifies the bit depth for text anti-aliasing. Possible values are -sSUBSTFONT=<fontname>
1 (=no anti-aliasing), 2, and 4. Note that only few drivers are ca- Selects the named font as substitute for all missing fonts. This
pable of anti-aliasing. disables Ghostscript’s normal font substitution mechanism.
-dWRITESYSTEMDICT
Systemdict remains writable. This is necessary for some utility 5.2 Environment Variables
programs that must bypass normal PostScript access protection,
GS_DEVICE=<device>
such as font2c and pcharstr. Defines the initial output device driver.
-sDEVICE=<device> GS_FONTPATH=<path>
Select the initial output device driver. Specifies a list of directories that should be scanned for fonts at
startup (see section 2.5, »Font Configuration«).
This works for displaying and printing PDF files and for con- Encrypted PDF files. PDF files may optionally contain en-
verting them to PostScript (see below). crypted data. PDF encryption uses a combination of the MD5
and RC4 algorithms. Although code for these algorithms is
Converting PDF files to PostScript. Ghostscript is able to
publicly available, current U.S. export regulations make it im-
convert PDF files back to PostScript Level 2. In fact, if the PDF
possible to include the code necessary for reading encrypted
file doesn’t contain compressed raster graphics or color spaces,
PDF files in the Ghostscript distribution. You may, however, re-
the generated PostScript files use Level 1 operators only. The
trieve a simple add-on file from the following URL:
following command line creates the corresponding PostScript
file for a PDF file: http://www.ozemail.com.au/~geoffk/pdfencrypt
gs -dNODISPLAY -sPSFile=file.ps file.pdf Of course this file doesn’t contain a code-cracker: you still need
the password to open encrypted PDF files.
A little shell script/batch file contained in the Ghostscript dis-
tribution makes this even easier: PDF files in GSview and Ghostview. Note that because of
pdf2ps file.pdf file.ps the idiosyncrasies of the PDF format Ghostscript isn’t able to
The following additional options are available for PDF to Post- read PDF files from its standard input. Due to this fact, display-
Script conversion: ing PDF files with Ghostview has its limitations. You can use
the following command line for Ghostview on Unix to browse
-dPSBinaryOK PDF files one page after the other. It’s not possible to jump to
Allows the generated PostScript files to contain binary data. arbitrary page numbers:
-dPSLevel1 ghostview -arguments file.pdf quit.ps
Generates PostScript Level 1 output. GSview for Windows and OS/2 has already been adapted to
-dPSNoProcSet processing PDF files. GSview handles PDF files just as Post-
Does not include the PostScript prolog (procset) in the output. Script files. Jumping to an arbitrary page in the file is also
Note that the prolog is necessary when sending the generated possible.
file to a PostScript printer.
Extracting text from PDF files. Using the ps2ascii.ps or
Converting PostScript to PDF (distilling). Ghostscript is pstotext utilities you can extract text from PDF files (see next sec-
also able to “distill” PostScript files to PDF. The following com- tion for details).
mand line can be used to distill PostScript files to PDF:
gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite 6.3 Printing and Extracting Text
-sOutputFile=file.pdf file.ps
Printing text files. The gslp.ps utility program implements a
Again, a shell script/batch file simplifies the process:
lineprinter emulation, i.e., printing simple text files with Post-
ps2pdf file.ps file.pdf Script commands. This includes some formating such as head-
Examples
• How to port EPS files or fonts from Mac to Windows to Unix
• Pros and cons of different PostScript drivers for Windows
• How to install PostScript fonts in the X Window System
• How to interpret and fix PostScript error messages
• How to edit or create PostScript fonts
• How to make EPS files editable again
• What's the Control-D business with PostScript files?
• How to make use of Level 2 without a Level 2 savvy driver
• How to create hypertext features in PDF files automatically
• How to use PDF files without Acrobat software
• Linking PDF files to the World Wide Web
• Performance optimization and prepress issues
Contents
Basics – Between Monitor and Printer – Encapsulated PostScript (EPS) – PostScript Fonts – PostScript Level 2
– Gray Levels and Color – Display PostScript – Adobe Acrobat and PDF – Miscellaneous – Software on the
CD-ROM – Ghostscript Manual – Character Sets