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.
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.psThis 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 ~/.XdefaultsIf 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.
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.pswhich 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.psThe default units are inches. The image's X origin can be shifted similarly.
- Easy Watermarking with ImageMagick
- The Only Mac I Use
- Promise Theory—What Is It?
- Integrating Trac, Jenkins and Cobbler—Customizing Linux Operating Systems for Organizational Needs
- New Products
- Tech Tip: Really Simple HTTP Server with Python
- RSS Feeds
- Returning Values from Bash Functions
- Raspberry Pi: the Perfect Home Server
Editorial Advisory Panel
Thank you to our 2014 Editorial Advisors!
- Jeff Parent
- Brad Baillio
- Nick Baronian
- Steve Case
- Chadalavada Kalyana
- Caleb Cullen
- Keir Davis
- Michael Eager
- Nick Faltys
- Dennis Frey
- Philip Jacob
- Jay Kruizenga
- Steve Marquez
- Dave McAllister
- Craig Oda
- Mike Roberts
- Chris Stark
- Patrick Swartz
- David Lynch
- Alicia Gibb
- Thomas Quinlan
- Carson McDonald
- Kristen Shoemaker
- Charnell Luchich
- James Walker
- Victor Gregorio
- Hari Boukis
- Brian Conner
- David Lane