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

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState