Working With The Guts Of PostScript

Lots of people fly in airplanes, but few understand how aviation works. That’s why many of us cling to erroneous ideas about flying, believing that air turbulence is dangerous, say, and can even cause an airplane to fall out of the sky. For these unfortunate travelers, ignorance is not bliss; it’s the cause of unnecessary anxiety.

PostScript is what makes desktop publishing fly–it’s the underlying structure on which many magazines, books, and newspapers are built. Sure, you can use QuarkXPress or Adobe InDesign without knowing anything about PostScript, just as you can fly without understanding the physics of lift. But knowing even a littie about PostScript can go a long way: it can help you predict what’s going to come out of your printer, saving you time and frustration. It can also help you troubleshoot problems. And with a smattering of PostScript, you can do a few tricks you may not have thought possible (see “Zap the Big White Box”).

PostScript 101

qePostScript is a programming language that describes text and graphics on a page. Its commands control where a Laser printer (or any PostScript device) places a line of text, a circle, a Bezier curve, or a bitmapped image. Although you can easily write your own code (see “PostScript Unveiled”), few people actually write PostScript anymore; instead, programs such as Macromedia FreeHand, QuarkXPress, and Apple’s LaserWriter driver write PostScript commands to a disk file and then send the file to the printer. The printer’s interpreter reads the PostScript commands and converts them to marks on the page.

Adobe Systems originally wrote PostScript and licenses it, but many other companies have built interpreters that can read PostScript. Adobe has released three different versions over the years: PostScript, PostScript Level 2, and PostScript 3. While most imaging devices today can handle Level 2 commands, only newer printers can deal with PostScript 3 commands (including the ability to process native Adobe Acrobat PDF files and perform in-printer trapping). Ultimately, for the sake of compatibility with older devices, few programs and drivers take advantage of the higher-level commands available in Level 2 and PostScript 3.

Page-Building Basics

Knowing how PostScript builds pages is helpful in understanding how desktop publishing applications work–and why your output may not always look the way you expect it to. PostScript describes a page one object (a circle, some text, or whatever) at a time, with each object sitting on top of the previous objects. In QuarkXPress, you might create a text box that has a solid white background and the word Macworld in it. When you print, QuarkXPress and the LaserWriter driver together convert this image into PostScript: the PostScript file describes the rectangle, fills it with white, and then places the text on top of it. (If the text contains any type effects, such as kerning, PostScript may place the text one character at a time.)

There’s a common myth that it takes longer to print a QuarkXPress page if your text boxes have a background of None. As this example shows, that’s balderdash. If the text box were transparent rather than white, the only difference would be that the PostScript commands would not paint the box white before placing the text. Therefore, it’s actually faster to print transparent text boxes, though the difference is only a fraction of a second.

PostScript is an opaque imaging model, which means that whatever you place on the page will totally cover what’s beneath it. If you use PostScript to describe a 50 percent gray box on your page and then put a 20 percent gray box on top of it, you don’t get a 70 percent gray box. Instead, you see only the 20 percent gray box. Whatever is on top takes precedence.

The fact that PostScript describes opaque objects also explains why there’s no such thing as a truly transparent object in PostScript (although hopefully Adobe will address this limitation). If you place a soft drop shadow on top of something else in QuarkXPress, you can’t see through the shadow because, again, whatever is on top entirely covers what’s underneath. Any program that offers a transparency feature has to fake this effect when it prints your page.

Errors in Interpretation

A common incentive to learn PostScript is the alarming “PostScript Error” message that stops a print job dead in its tracks. PostScript is a very sensitive language; even a small error can wreak havoc on your page. For instance, a command called “lineto” draws a line from one page coordinate to another. If your computer makes an error when writing the PostScript code, it might write this command as “lneto.” Because the interpreter won’t know what this command means, it will respond with the “Undefined Command” error. Another common error, especially on older printers, is “Limitcheck,” which occurs when some internal limit has been exceeded. For instance, old devices can’t handle long, complex Bezier curves and may return a “Limitcheck” error if you don’t simplify the shape.

To find out exactly what the error is when using QuarkXPress or Adobe PageMaker, turn on the error-handling feature in the Print dialog box. In other programs, you can choose Error Handling from the General pop-up menu in the Print dialog box (if you don’t see this pop-up menu, you’re using an older LaserWriter driver). Either way, you’ll get a page that lists the offending command and the type of error. If it’s an “Undefined Command” error, something’s wrong with the print stream and your best bet is to send the job again. If you see “Limitcheck,” you should try to simplify the file’s contents.

The Future of PostScript

Although PostScript has long been at the core of desktop publishing, the industry is moving toward using Acrobat PDF as the standard imaging language. But there’s life in the old language yet: because Adobe originally based the PDF specification on PostScript, knowledge of PostScript is very useful in understanding how Acrobat works, too. And it’ll be years before PDF fully replaces PostScript. Until the majority of imaging devices can read native PDF files, these documents will still require translation (usually by a printer driver) into PostScript.


POSTSCRIPT LOOKS DIFFICULT, BUT IT’S ACTUALLY A PRETTY SIMPLE LANGUAGE. Because it’s almost always just plain text, you can use any text editor to write or edit it (don’t use a word processor such as Microsoft Word; it might add formatting). I often use Bare Bones Software’s BBEdit ( because it also lets you download PostScript to the printer quickly to see your results.

Here’s a sample PostScript program that draws a series of boxes (you can type this code in or download it from Open any EPS file and you’ll see something similar: an EPS file starts with all the procedures it’s going to use and ends with the actual commands to makemarks on a page. (EPS files don’t include the showpage command, though.)

When you’ve finished writing your program, save it as a text file and download it to your printer. If you use BBEdit, you can choose Send PostScript from the Tools menu. Or you can use another utility, such as Adobe Font Down-loader, to send the file.

(1) Lines that begin with a percent sign are comments, and the interpreter ignores them. The one exception is this first line, which some interpreters require to inform them that the following file is Postscript.

(2) A slash at the beginning of a line identifies a procedure that we’ll use multiple times later in the program. Procedures are always defined inside curly brackets and end with def. We’ve called this procedure drawbox (but you can call procedures almost anything you want).

(3) The program does all drawing on a giant grid, and there are generally 72 points per inch. Here, we set PostScript’s virtual drawing tool to the (0,0) coordinate; the program then draws a line 100 points to the right and 0 points vertically. Note that in Postscript, the values (in this case, coordinates) always come before the command. This is called putting values on the “stack.”

(4) The closepath command makes the open-ended line into a closed box. The box doesn’t actually appear until you stroke or fill it. In this case, stroke instructs the printer to paint the line with the default 1-point rule but not to fill the box.

(5) The (0,0) coordinate is usually at the lower-left corner of the page. The translate command tells the printer to move (0,0) to a different coordinate–in this case, 250 points from the left edge of the paper and 350 points up from the bottom of the page. We’ve already specified a procedure, so we can call it by name anytime. The program draws the box.

(6) Here, the whole coordinate grid system rotates 15 degrees and the program draws the box again. This way, you don’t have to figure out new coordinates for the box’s corners. In this case, each time you give the rotate command, the grid rotates further. The second time you give the rotate command, the grid rotates a total of 30 degrees, and so on.

(7) The showpage command tells the imaging device to print the page. If you don’t include the command, then the program draws the virtual page but no paper comes out of your device.

Zap the Big White Box

HERE’S A REAL-WORLD EXAMPLE OF HOW EDITING POSTSCRIPT CAN SIMPLIFY YOUR life. QuarkXPress 4.X creates EPS files slightly differently from how previous versions did: it always draws a white box behind your page. If you are compositing your EPS file on top of some other image and want the background transparent, you’re out of luck–unless you can edit PostScript.

(1) Open the EPS file in a text editor such as BBEdit (word processors like Microsoft Word can mess up the text by adding formatting).

(2) Search for the line that reads %%EndSetup. Soon after it you’ll see another line that reads something like g np clippath 1 H V G calcbnd.

(3) The commands g, np, H, and so on are all procedures defined earlier in the file. Remove the characters 1 H V and save the file again. Those three characters create that white box (the 1 is the color white; if you were to change this to 0, the box would be black).


1 Comment

Tags: ,

One comment on “Working With The Guts Of PostScript

  1. Blake Cranston on said:

    I remember the beginnings of postscript. Dealing with crappy Apple printers and constantly trying to debug imaging issues.

    Not my favorite thing, and I’m glad print is dying. You suck Adobe!

Leave a Reply

Your email address will not be published. Required fields are marked *


HTML tags are not allowed.