GNU Ghostscript

Need to preview and print PostScript Files? Here's a utility that will do just that.

Viewing an Encapsulated PostScript recycling logo in a TeX document should have been simple enough. Instead, a blank space marked the position on the display where the logo should have appeared. A quick look through all of my LaTeX documentation, including the xdvi man page, provided no answer. There seemed to be no way for xdvi to display a TeX \special command in the dvi output; in this case, an embedded PostScript image. I considered this to be a major shortcoming of xdvi, and, of course, TeX. After all, isn't combining text and graphics on a page part of what computer publishing is all about? Why should TeX, one of the most sophisticated typesetting systems in the world, be constrained by the lack of a PostScript previewer? Or the requirement for a PostScript printer, for that matter? It is said that the longest journey begins with a single step. The journey I'm about to describe has brought me a considerable distance toward professional-quality publishing, via a utility that had been sitting quietly in a subdirectory of my /usr partition all along.

The utility is Ghostscript. GNU Ghostscript, Version 3.33, is the Swiss Army knife of graphics programs. Essentially, it's a PostScript language interpreter. More specifically, Ghostscript renders PostScript code to any bitmapped device on your system, whether it be the screen, printer, or G3 fax file. The man page says, “Ghostscript is a programming language similar to Adobe System's PostScript language, which is in turn similar to Forth.” (This statement comes almost verbatim from the book: Adobe Systems, Incorporated: PostScript: Language Tutorial and Cookbook, Addison-Wesley, 1986.) Ghostscript also substitutes fonts from its own library when rendering documents if the fonts are not otherwise available, scales and rotates text, and performs any of the other typographical feats for which PostScript is famous. Despite the apparent complexity of the task, no knowledge of the PostScript language is required. For the most part, a little experimentation with the command-line options is all that's needed. Yet Ghostscript's PostScript interpreter is fully accessible.

If I want to print that EPS recycling logo at the bottom of a page of DVI output, I would insert the following commands in my LaTeX input file:

\usepackage{graphics} ... \vfil \includegraphics{recycle.eps}

Then, it is simply a matter of running the input file through teTeX, using the command line:

pslatex letter.tex
and then converting teTeX's dvi output to PostScript with dvips:
dvips -f <letter.dvi >letter.ps
The -f command-line option tells dvips to act as a filter, reading from standard input and writing to standard output. Now, we have a PostScript file ready for printing. Ghostscript images this file in a format that's understandable to any bitmapped device on your system, whether it is a VGA display or a laser printer.

Ghostscript's command-line options are numerous. Look at ghostscript's USE.DOC file for an complete description. You can view a brief summary with the command:

gs -help | less

For example, if I want to print the file letter.ps on a Hewlett Packard DeskJet printer, I would use the command line:

gs -q -dNOPAUSE -sDEVICE=deskjet
/-sOutputFile=-\
         letter.ps quit.ps >gs.out
The first option, -q, suppresses messages to the console. However, to run Ghostscript in batch mode, the -q option on its own is not enough. That's because Ghostscript uses its own PostScript code at run time to output the image.

From the command line, we define several variables, the first being NOPAUSE, which tells Ghostscript's showpage() routine not to pause after each page is output. When viewing output on a screen, it is best to leave NOPAUSE unset and let Ghostscript prompt you to view each page in turn.

Next, we set the DEVICE variable. In the example above, the output device is a HP Deskjet. Ghostscript's dictionary has output parameters defined for all the devices documented in its command-line help.

The next variable which needs defining is OutputFile. Here, we set it to - or standard output. This is the file to which Ghostscript will write its image. In most instances, however, Ghostscript provides no means for that image to be displayed. We'll get to that in a moment. Then we specify letter.ps on the command line as our target input file.

When we write a file with the pslatex command, LaTeX uses the font metrics available to it; that is, it uses Computer Modern Roman as its default font. However, the pslatex command has been implemented in teTeX so that dvips, which does the DVI to PostScript conversion, will request PostScript fonts. These fonts can be provided via either the printer or via software. In the latter case, Ghostscript produces the output image using Type 1 fonts from its own library.

Finally, we input the file quit.ps. This file is part of Ghostscript's standard library and is simply the command quit followed by a newline character. It is read into the Ghostscript interpreter just like any other input.

______________________

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Emacs Tex mode printing via Ghostscript shell scripts

Anonymous's picture

The section "Ghostscript as a Document Post-Processor and Previewer" of this article sounds very interesting but doesn't work. More explanation would be nice.
Alex.

Re: Emacs TeX mode printing via Ghostscript shell scripts

Anonymous's picture

Try to isolate the problem. Do the individual utilities run correctly from the shell prompt? Then, do the shell scripts run correctly from the shell? If they don't, then try to include the error messages. If they do, then try to include the debug output from the Emacs interpreter. Also include the version of each utility, so I can duplicate the errors produced by newer versions. Or, you can follow these procedures, and submit a patch.

Robert Kiesling

Webinar
One Click, Universal Protection: Implementing Centralized Security Policies on Linux Systems

As Linux continues to play an ever increasing role in corporate data centers and institutions, ensuring the integrity and protection of these systems must be a priority. With 60% of the world's websites and an increasing share of organization's mission-critical workloads running on Linux, failing to stop malware and other advanced threats on Linux can increasingly impact an organization's reputation and bottom line.

Learn More

Sponsored by Bit9

Webinar
Linux Backup and Recovery Webinar

Most companies incorporate backup procedures for critical data, which can be restored quickly if a loss occurs. However, fewer companies are prepared for catastrophic system failures, in which they lose all data, the entire operating system, applications, settings, patches and more, reducing their system(s) to “bare metal.” After all, before data can be restored to a system, there must be a system to restore it to.

In this one hour webinar, learn how to enhance your existing backup strategies for better disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible bare-metal recovery solution for UNIX and Linux systems.

Learn More

Sponsored by Storix