Featured image of post Postscript in a nutshell

Postscript in a nutshell

Intro to the PostScript Language

Deep Dive into the PostScript Language

So, you want to dive deep into PostScript, huh? Well, buckle up, because we’re about to take a trip down memory lane—back to the days when Steve Jobs was young, Xerox ruled the tech world, and printers needed a PhD to print a simple document.

A Brief History of PostScript

PostScript is the reason why your printer doesn’t just spit out garbled nonsense when you send it a PDF. It was created in the early 1980s by Adobe Systems, founded by former Xerox employees John Warnock and Charles Geschke.

Here’s how it all connects:

  • Xerox PARC developed much of the technology that led to PostScript, but they famously fumbled the ball (again) and let Adobe run with it.
  • Apple and Steve Jobs saw the potential, licensing PostScript for the LaserWriter in 1985—this was the first laser printer to include PostScript.
  • Adobe made bank, and PostScript became the industry standard for printing and desktop publishing.
  • PDF (Portable Document Format) is basically a direct descendant of PostScript, designed for documents that need to be displayed consistently across devices.

If you want to geek out more, check out:


How PostScript Works

PostScript is a Turing-complete programming language. That’s right! Your printer is basically a tiny computer running a programming language.

It’s a stack-based language, similar to Forth or RPN (Reverse Polish Notation) calculators. Commands (called “operators”) manipulate a stack, meaning order matters.

Example 1: Basic Stack Manipulation

1
10 20 add
  • 10 and 20 are pushed onto the stack.
  • add pops them off, adds them, and pushes the result (30) back onto the stack.

Debugging PostScript

PostScript is not the friendliest language to debug, but here’s how you can do it without wasting paper:

1. Use Ghostscript

Ghostscript is your best friend for running and debugging PostScript files on your computer.

Run a PostScript file with:

1
gs myfile.ps

2. Debugging with == and print

  • “==” prints the top of the stack.
  • “print” prints a string.

Example:

1
(Hello, PostScript!) print

Testing PostScript Files Without Printing

If you don’t want to hear your printer scream in agony while testing, use:

  1. Ghostscript
  2. PostScript viewers like GSView or MuPDF
  3. Converting PostScript to PDF using:
    1
    
    ps2pdf myfile.ps myfile.pdf
    

Essential PostScript Commands with Examples

CommandDescriptionExample
movetoMoves the pen to a position100 100 moveto
linetoDraws a line from the current position200 200 lineto
strokeRenders the drawn pathstroke
fillFills a shapefill
showPrints text(Hello!) show
setlinewidthSets line thickness5 setlinewidth
setrgbcolorSets color (RGB)1 0 0 setrgbcolor (red)

Example: Drawing a Red Line

1
2
3
4
5
6
7
newpath
100 100 moveto
200 200 lineto
1 0 0 setrgbcolor
5 setlinewidth
stroke
showpage

Example: Drawing a Rectangle

1
2
3
4
5
6
7
8
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
stroke
showpage

1. Drawing a Circle

1
2
3
4
newpath
200 200 50 0 360 arc
stroke
showpage

This draws a circle with a radius of 50 centered at (200, 200).

2. Drawing a Triangle

1
2
3
4
5
6
7
newpath
100 100 moveto
200 300 lineto
300 100 lineto
closepath
stroke
showpage

Simple triangle with three points connected.

3. Rotating an Object

1
2
3
4
5
6
7
8
gsave
200 200 translate
45 rotate
0 0 moveto
100 0 lineto
stroke
grestore
showpage

This rotates a line by 45 degrees.

4. Scaling an Object

1
2
3
4
5
6
7
gsave
2 2 scale
100 100 moveto
200 100 lineto
stroke
grestore
showpage

Doubles the size of a line.

5. Setting a Custom Font and Printing Text

1
2
3
4
5
6
/Times-Roman findfont
24 scalefont
setfont
100 400 moveto
(Hello, PostScript!) show
showpage

Uses Times-Roman font at 24pt size.

6. Drawing a Star

1
2
3
4
5
6
7
8
9
newpath
100 200 moveto
150 50 lineto
200 200 lineto
50 100 lineto
250 100 lineto
closepath
stroke
showpage

Five lines creating a simple star.

7. Creating a Gradient Effect

1
2
3
4
5
6
7
8
9
0 0 0 setrgbcolor
0 0 moveto
300 0 lineto
300 300 lineto
0 300 lineto
closepath
1 0 0 setrgbcolor
fill
showpage

Fills a square with a red color.

8. Making a Dashed Line

1
2
3
4
5
[4 2] 0 setdash
100 100 moveto
300 100 lineto
stroke
showpage

Creates a dashed line with a repeating pattern of 4 pixels on, 2 pixels off.

9. Clipping an Area

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
newpath
100 100 moveto
200 100 lineto
200 200 lineto
100 200 lineto
closepath
clip
newpath
50 50 moveto
250 250 lineto
stroke
showpage

Restricts drawing to a clipped square area.

10. Using Loops to Draw Multiple Lines

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/square {
  newpath
  0 0 moveto
  50 0 lineto
  50 50 lineto
  0 50 lineto
  closepath
  stroke
} def

100 100 translate

5 {
  square
  10 10 translate
} repeat

showpage

Draws five squares in a row using a loop.


Reference Table: PostScript Commands

Here’s a handy cheat sheet:

CommandFunction
newpathStarts a new drawing path
moveto x yMoves to (x, y) without drawing
lineto x yDraws a line to (x, y)
curveto x1 y1 x2 y2 x3 y3Draws a Bézier curve
closepathCloses the path (connects back to start)
strokeRenders the path as an outline
fillFills the shape
showpageEnds the page and prints it
setrgbcolor r g bSets the color
setlinewidth nSets line thickness
gsave / grestoreSaves/restores graphic state

For a complete reference: Adobe PostScript Reference


Key Takeaways

  • PostScript is a programming language used for printing.
  • It’s stack-based, meaning operations work in a last-in, first-out manner.
  • It’s the ancestor of PDF, still used in professional printing.
  • You can test PostScript without a printer using Ghostscript and viewers.
  • It has a ton of commands, but at its core, it’s all about moving pens and drawing shapes.

PostScript vs. HP’s PCL: The Printer Wars

If you’ve ever dealt with printers, you might have heard about PCL (Printer Command Language), which is HP’s answer to PostScript. These two have been battling it out in the printing world for decades.

A Brief History of Postscript vs PCL

  • PostScript (Adobe) was introduced in the 1980s and became the standard for high-end professional printing.
  • PCL (HP) was developed by Hewlett-Packard in 1984 as a simpler, more efficient alternative to PostScript for personal and office printers.
  • The difference? PostScript is device-independent, meaning it produces the same output no matter the printer, while PCL is faster but more hardware-dependent.

Key Differences Between PostScript and PCL

FeaturePostScriptPCL
DeveloperAdobeHP
Device IndependenceYesNo
ComplexityMore complexSimpler
SpeedSlower (interpreted language)Faster (directly understood by printers)
Graphics QualityHigh precisionFaster but less precise
UsageHigh-end printing, publishingGeneral office printing

Why PostScript Still Matters

Even though PCL is often used in office printers due to speed and simplicity, PostScript remains the king for graphic designers, publishers, and high-quality printing. If you’re printing a complex PDF or a detailed image, PostScript will ensure it looks the same on any printer.

If you just need fast text printing, PCL is great. If you want perfect graphics and consistency, PostScript wins every time.


References

  1. Wikipedia: PostScript
  2. Adobe PostScript Reference Guide
  3. Ghostscript
  4. Xerox PARC
  5. PostScript Tutorials