GNU Ghostscript

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

Viewing images on-screen is only a little more difficult. Ghostscript for Linux comes with both X11 and SVGALib support. The executables for both versions should be in the /usr/bin directory: gs-with-X11 and gs-without-X11. You can run either version using its actual file name, but the more common implementation uses a soft link of the actual executable to the gs command. In either case, the executable's permissions should be setuid root so it can access the display. We'll describe how to use Ghostscript as a PostScript previewer with both the X Window System and SVGALib.

Ghostscript with X11

The X Window System provides a lot of the display support that Ghostscript would need to provide otherwise. As a result, it is by far the way to use Ghostscript as a previewer. As with the above example, we want to pass letter.tex through LaTeX and then convert the output to PostScript with the command line:

pslatex letter.tex; \
        dvips -f <letter.dvi >letter.ps

Again, we need to specify the DEVICE string to gs, which is simply X11 for the X display. Ghostscript treats an X11 display frame as the standard output, and the X display services provide the geometry to display an entire page. A virtual window manager like FVWM already provides the facilities to scroll the view over the entire page. The ghostscript command, then, is simply:

gs -r72 -sDEVICE=X11 letter.ps
This will provide us with an actual-size page on the screen, because we've overridden the default resolution with the -r switch.

A VGA display provides about 72 dots per inch resolution, so a legible, actual-size full U.S. letter page will not fit on the screen. This is why we rely on FVWM or another virtual window manager to scroll the view across the entire page. Ghostscript draws a page-high window on your X display. About half of the page is visible at a time. You can, of course, view the full page at twice its actual size by specifying your output resolution as 36dpi.

The simplest way to execute the Ghostscript command is in an xterm window. The page appears in a window which displays the child process of the Ghostscript command. Ghostscript writes its messages to standard error, which here is the xterm. Pressing enter in the xterm window tells showpage to display each successive page of Ghostscript output. You can set the default resolution in your ~/.Xdefaults file by adding the lines:

Ghostscript*xResolution: 72 Ghostscript*yResolution: 72

and then merge the defaults with the other X server defaults:

xrdb -merge ~/.Xdefaults
If the resolution isn't specified, the page is displayed on the screen at 300dpi, about one-quarter its actual size, which is visible in a 640x480 view without scrolling.

Ghostscript with SVGALib

Things get a little more difficult when using a VGA display without X11 support. A standard Linux tty device provides no ready-made provision for paging over a full, U.S. letter-size image. Also, Ghostscript's SVGALib routines must be provided with geometry and resolution information to preview images. The following information is specific to my Compaq laptop, Chanel3, which has a 16 color, 640x480 standard VGA display, GNU Ghostscript Version 3.33 and SVGALib version libvga.so.1.2.10. You'll need to adjust the parameters to suit your hardware, but the basic procedure should be similar.

The settings that Ghostscript recognizes for various hardware configurations are listed in use.doc file and the gs man page. The DEVICE string is “linux” for a Linux virtual console; that is:

/dev/tty1 - /dev/tty9

This string corresponds to the virtual console's /etc/termcap entries. The -r resolution, parameter is one of several dozen VGA modes that SVGALib recognizes. Ghostscript defines single-digit mode numbers which correspond to standard width-by-height notation. There is a complete list in the Ghostscript man page. In this case, Mode 4 is 16-color, 640x480 VGA. Much of the following information depends on whether SVGALib provides information on display geometry for your particular display. Ghostscript requires this information to display anything. It must be provided, for one thing, with the aspect ratio of the display (the ratio of the display's width to its height) in order to scale the fonts correctly.

The geometry parameter (-g) tells Ghostscript the display dimensions. Ghostscript scales the output page to the geometry we specify. We'll address this problem in a moment. With these parameters set, our Ghostscript command is:

gs -sDEVICE=linux -r4 -g640x480 letter.ps

Remember that gs is really a link to the executable file /usr/bin/gs-without-X11. Here, we tell Ghostscript to display a full page by specifying a display geometry that's twice the size of the actual screen. This gives us a page that is slightly more than twice as large as the video display. To double the size of the virtual display—the “device space” in PostScript jargon—we use the command line:

gs -sDEVICE=linux -r4 -g640x960 letter.ps
which gives us an actual-size view of the top half of the printed page. To view the bottom half of the page, we can specify an offset of the image's Y origin as half of a U.S. letter-size page:
gs -sDEVICE=linux -r4 -g640x960 -dYO=5.5
letter.ps
The default units are inches. The image's X origin can be shifted similarly.

______________________

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