Getting Started With Postscript
To get started with Postscript some tools are required. For this tutorial, GhostScript will be used as the postscript interpreter. GSview will also be used which is a nice viewer that works on top of GhostScript. GhostScript could do everything that is done in the tutorial without GSview but GSview is very handy and quicker than learning all the GhostScript specific features.

GhostScript & GSview Install
GhostScript can be obtained from as well as GSview. Downloading either the AFPL or GNU version of GhostScript. There are downloads for Macintosh, Windows, and Linux/Unix. Grab both GhostScript and GSview and run the installers. The default location is fine.

When running GhostScript alone, it works as a command line Postscript interpreter. Next in this tutorial a discussion on postscript basics will go over basic usage of GhostScript.

PostScript Basics
Postscript is a language that was designed by Adobe and was intended for printing graphics. Postscript can be used to describe graphics with device independence. This allows any postscript printer to print the same thing.

Postscript can be written by hand to make graphics or to describe a page for print. But normally postscript is written by a program that converts what the user puts on the page. In this tutorial and the tutorials to follow we will be writing our programs by hand and getting to know the language features.

Hello World!

Every good tutorial on programming has a Hello World example. Okay so maybe not all of them but we will do one just for fun. Type the following into a file called

/Times-Bold findfont 30 scalefont setfont
100 300 moveto (Hello World!) show

If you have installed GSview properly then all you have to do is save this file and open it in GSview. Then you will se the page that you created. We are not going to discuss this program much but the basics used in the program will be covered.

Means of Combination:

PS Stack:

  • LIFO - Last in First Out
  • Numbers that appear in code are placed on the stack
  • Any PS object can be pushed onto the stack
  • Memory set aside for data that will be used immediately

Basic stack operations - These are just some of the basic stack operations that will be used. There are others that can be really hand to manipulating data on the stack that will be discussed later.

  • Push a number on the stack - In ghostscript type the number and on it goes.
  • Pop a number off the stack - type pop and this removes the top element
  • Print the Stack - type pstack and the stack will print itself and remain intact. to print the top element do == which will remove the top element and print it.

Primitive Elements:

Data Types Common Operators
Numbers - real numbers and integers add
Strings - Enclosed in parentheses sub
Arrays mul
Boolean Values div
Dictionaries mod
Marks neg

Problem: we will be evaluating 6 + (3 / 8). How many ways can you write this and achieve the right answer?

Means of Abstraction:

Postscript supports creating procedures which as we all know will make a program more readable and will shorten the amount of code we have to write. To make procedure the name starts with a / and then any name like /foo to name the procedure foo. The in curly braces the procedure is written and finally the word def it put at the end. Here is an example of a competed procedure:

/inch {72 mul} def

This procedure will add the number 72 to the stack and then multiply. This is a commonly used procedure since there is 72 points in postscript in an inch. This is how we use this function:
5 inch

and we will be left with 360 as the top element of the stack which is how many points there are in 5 inches.

More Stack Operators:

There are more stack operators than those discussed above. These operators provide for more manipulation of the stack and can be really handy.

clear - removes everything from the stack
dup - duplicates the top element of the stack
exch - exchanges or swaps the top two elements of the stack
roll - rotates the stack the top number on the stack is how many times to rotate and the second number is how many numbers to rotate.


  1. Experiment with the stack operators.
  2. Experiment with the arithmetic operators.
  3. Where or how would the roll operator come in use?

***Note: Experiment with the stack until you feel comfortable with it. The stack is used everywhere so it is very important that you understand the stack and the basic operations that can be done.

The PostScript Tutorial Concieved and Created by Dann Ormond & Will Munn. Inspired by Mike Grady PhD. Website Design by