by Vadim Pavlov
http://doc.thesa.ru

PostScript Operators Quick Reference

This document contains summary information about all the standard operators in the PostScript language, organized into groups of related functions. Each operator description is presented in the following format:

operand1 operand2 ... operandn     operator result1 ... resultm explanation of the operator

At the head of an operator description, operand1 through operandn are the operands that the operator requires, with operandn being the topmost element on the operand stack. The operator pops these objects from the operand stack and consumes them. After executing, the operator leaves the objects result1 through resultm on the stack, with resultm being the topmost element.

Normally, the operand and result names suggest either their types or their uses. The table below shows common operand and result types used in this reference.

   Name Description
   angle Angle (in degrees)
   any Value of any type
   boot Boolean (true or false) value
   context Integer representing an execution context
   dict Dictionary object
   font Font dictionary
   form Form dictionary
   halftone Halftone dictionary
   int Integer number
   matrix Array of six numbers describing a transformation matrix
   num Number (integer or floating point)
   numarray Array of numbers
   numstring Encoded number string
   pattern Pattern dictionary
   proc Procedure (executable array or executable packed array)
   real Floating point (real) number
   userpath Array of path construction operators and their operands

Some operators are polymorphic: their operands may be any of several types. For example, the notation file | proc | string indicates an operand that is a file, procedure, or string.

The notation "|-" indicates the bottom of the stack. The notation "-" in the operand position indicates that the operator expects no operands, and a "-" in the result position indicates that the operator returns no results.

The documented effects on the operand stack and the possible errors are those produced directly by the operator itself. Many operators invoke arbitrary PostScript language procedures. Such procedures can have arbitrary effects that are not mentioned in the operator descriptions.

Operand Stack Manipulation Operators

any     pop - discard top element
any1 any2     exch any2 any1 exchange top two elements
any     dup any any duplicate top element
any1 ... anyn n     copy any1 ... anyn any1 ... anyn  duplicate top n elements
anyn ... any0 n     index anyn ... any0 anyn duplicate arbitrary element
an-1 ... a0 n j     roll a(j-1) mod n ... a0 an-1 ... aj mod n  roll n elements up j times
|- any1 ... anyn     clear |- discard all elements
|- any1 ... anyn     count |- any1 ... anyn n count elements on stack
-     mark mark push mark on stack
mark obj1 ... objn     cleartomark - discard elements down through mark
mark obj1 ... objn     counttomark mark obj1 ... objn n count elements down to mark


Arithmetic and Math Operators

num1 num2     add sum num1 plus num2
num1 num2     div quotient num1 divided by num2
int1 int2     idiv quotient integer divide
int1 int2     mod remainder int1 mod int2
num1 num2     mul product num1 times num2
num1 num2     sub difference num1 minus num2
num1     abs num2 absolute value of num1
num1     neg num2 negative of num1
num1     ceiling num2 ceiling of num1
num1     floor num2 floor of num1
num1     round num2 round num1 to nearest integer
num1     truncate num2 remove fractional part of num1
num     sqrt real square root of num
num den     atan angle arctangent of num/den in degrees
angle     cos real cosine of angle (degrees)
angle     sin real sine of angle (degrees)
base exponent     exp real raise base to exponent power
num     ln real natural logarithm (base e)
num     log real logarithm (base 10)
-     rand int generate pseudo-random integer
int     srand - set random number seed
-     rrand int return random number seed


Array Operators

int     array array create array of length int
-     [ mark start array construction
mark obj0 ... objn-1     ] array end array construction
array     length int number of elements in array
array index     get any get array element indexed by index
array index any     put - put any into array at index
array index count     getinterval subarray subarray of array starting at index for count elements
array1 index array2     putinterval - replace subarray of array1 starting at index by array2
any0 ... anyn-1 array     astore array pop elements from stack into array
array     aload a0 ... an-1 array push all elements of array on stack
array1 array2     copy subarray2 copy elements of array1 to initial subarray of array2
array proc     forall - execute proc for each element of array


Packed Array Operators

any0 ... anyn-1     packedarray packedarray create packed array consisting of the specified n elements
-     currentpacking bool return array packing mode
bool     setpacking - set array packing mode for {...} syntax (true = packedarray)
packedarray     length int number of elements in packedarray
packedarray index     get any get packedarray element indexed by index
packedarray index count     getinterval subarray subarray of packedarray starting at index for count elements
packedarray     aload a0 ... an-1 packedarray  push all elements of packedarray on stack
packedarray1 array2     copy subarray2 copy elements of packedarray2 to initial subarray of array2
packedarray proc     forall - execute proc for each element of packedarray


Dictionary Operators

int     dict dict create dictionary with capacity for int elements
-     << mark start dictionary construction
mark key1 value1 ... keyn valuen     >> dict end dictionary construction
dict     length int number of key-value pairs in dict
dict     maxlength int current capacity of dict
dict     begin - push dict on dictionary stack
-     end - pop dictionary stack
key value     def - associate key and value in current dictionary
key     load value search dictionary stack for key and return associated value
key value     store - replace topmost definition of key
dict key     get any get value associated with key in dict
dict key value     put - associate key with value in dict
dict key     undef - remove key and its value from dict
dict key     known bool test whether key is in dict
key     where dict true or false find dictionary in which key is defined
dict1 dict2     copy dict2 copy contents of dict1 to dict2
dict proc     forall - execute proc for each element of dict
-     currentdict dict push current dictionary on operand stack
-     errordict dict error handler dictionary
-     $error dict error control and status dictionary
-     systemdict dict system dictionary
-     userdict dict writable dictionary in local VM
-     globaldict dict writable dictionary in global VM
-     statusdict dict product-dependent dictionary
-     countdictstack int count elements on dictionary stack
array     dictstack subarray copy dictionary stack into array
-     cleardictstack - pop all non-permanent dictionaries off dictionary stack


String Operators

int     string string create string of length int
string     length int number of elements in string
string index     get int get string element indexed by index
string index int     put - put int into string at index
string index count     getinterval substring substring of string starting at index for count elements
string1 index string2     putinterval - replace substring of string1 starting at index by string2
string1 string2     copy substring2 copy elements of string1 to initial substring of string2
string proc     forall - execute proc for each element of string
string seek     anchorsearch post match true or string false  determine if seek is initial substring of string
string seek     search post match pre true or string false  search for seek in string
string     token post token true or false  read token from start of string


Relational, Boolean, and Bitwise Operators

any1 any2     eq bool test equal
any1 any2     ne bool test not equal
num1 | str1   num2 | str2     ge bool test greater or equal
num1 | str1   num2 | str2     gt bool test greater than
num1 | str1   num2 | str2     le bool test less or equal
num1 | str1   num2 | str2     lt bool test less than
bool1 | int1   bool2 | int2     and bool3 | int3 logical | bitwise and
bool1 | int1     not bool2 | int2 logical | bitwise not
bool1 | int1   bool2 | int2     or bool3 | int3 logical | bitwise inclusive or
bool1 | int1   bool2 | int2     xor bool3 | int3 logical | bitwise exclusive or
-     true true push boolean value true
-     false false push boolean value false
int1 shift     bitshift int2 bitwise shift of int1 (positive is left)


Control Operators

any     exec - execute arbitrary object
bool proc     if - execute proc if bool is true
bool proc1 proc2     ifelse - execute proc1 if bool is true, proc2 if bool is false
init incr limit proc     for - execute proc with values from init by steps of incr to limit
int proc     repeat - execute proc int times
proc     loop - execute proc an indefinite number of times
-     exit - exit innermost active loop
-     stop - terminate stopped context
any     stopped bool establish context for catching stop
-     countexecstack  int count elements on exec stack
array     execstack subarray copy exec stack into array
-     quit - terminate interpreter
-     start - executed at interpreter startup


Type, Attribute, and Conversion Operators

any     type name return name identifying the type of any
any     cvlit any make object be literal
any     cvx any make object be executable
any     xcheck bool test executable attribute
array | packedarray | file | string     executeonly array | packedarray | file | string reduce access to execute-only
array | packedarray | dict | file | string     noaccess array | packedarray | dict | file | string disallow any access
array | packedarray | dict | file | string     readonly array | packedarray | dict | file | string reduce access to read-only
array | packedarray | dict | file | string     rcheck bool test read access
array | packedarray | dict | file | string     wcheck bool test write access
num | string     cvi int convert to integer
string     cvn name convert to name
num | string     cvr real convert to real
num radix string     cvrs substring convert to string with radix
any string     cvs substring convert to string


File Operators

string1 string2     file file open file identified by string1 with access string2
src | tgt param1 ... paramn name     filter file establish filtered file
file     closefile - close file
file     read int true or false read one character from file
file int     write - write one character to file
file string     readhexstring substring bool read hex from file into string
file string     writehexstring - write string to file as hex
file string     readstring substring bool read string from file
file string     writestring - write string to file
file string     readline substring bool read line from file into string
file     token token true or false read token from file
file     bytesavailable int number of bytes available to read
-     flush - send buffered data to standard output file
file     flushfile - send buffered data or read to EOF
file     resetfile - discard buffered characters
file     status bool return status of file
string     status pages bytes referenced created true or false return information about named file
string     run - execute contents of named file
-     currentfile file return file currently being executed
string     deletefile - delete named file
string1 string2     renamefile - rename file string1 to string2
template proc scratch     filenameforall - execute proc for each file name matching template
file int     setfileposition - set file to specified position
file     fileposition int return current position in file
string     print - write string to standard output file
any     = - write text representation of any to standard output file
any     == - write syntactic representation of any to standard output file
|- any1 ... anyn     stack |- any1 ... anyn print stack non-destructively using =
|- any1 ... anyn     pstack |- any1 ... anyn print stack non-destructively using ==
obj int     printobject - write binary object to standard output file, using int as tag
file obj int     writeobject - write binary object to file, using int as tag
int     setobjectformat - set binary object format (0 = disable, 1 = IEEE high, 2 = low, 3 = native high, 4 = low)
-     currentobjectformat int return binary object format


Resource Operators

key instance category     defineresource instance register named resource instance in category
key category     undefineresource - remove resource registration
key category     findresource instance return resource instance identified by key in category
key category     resourcestatus status size true or false return status of resource instance
template proc scratch category     resourceforall - enumerate resource instances in category


Virtual Memory Operators

-     save save create VM snapshot
save     restore - restore VM snapshot
bool     setglobal - set VM allocation mode (false = local, true = global)
-     currentglobal bool return current VM allocation mode
any     gcheck bool true if any is simple or in global VM, false if in local VM
bool1 password     startjob bool2 start new job that will alter initial VM if bool1 is true
index any     defineuserobject - define user object associated with index
index     execuserobject - execute user object associated with index
index     undefineuserobject - remove user object associated with index
-     UserObjects array current UserObjects array defined in userdict


Miscellaneous Operators

proc     bind proc replace operator names in proc by operators
-     null null push null on operand stack
-     version string interpreter version
-     realtime int return real time in milliseconds
-     usertime int return execution time in milliseconds
-     languagelevel int level of language features
-     product string product name
-     revision int product revision level
-     serialnumber int machine serial number
-     executive - invoke interactive executive
bool     echo - turn on/off echoing
-     prompt - executed when ready for interactive input


Graphics State Operators - Device Independent

-     gsave - push graphics state
-     grestore - pop graphics state
-     grestoreall - pop to bottommost graphics state
-     initgraphics - reset graphics state parameters
-     gstate gstate create graphics state object
gstate     setgstate - set graphics state from gstate
gstate     currentgstate gstate copy current graphics state into gstate
num     setlinewidth - set line width
-     currentlinewidth num return current line width
int     setlinecap - set shape of line ends for stroke (0 = butt, 1 = round, 2 = square)
-     currentlinecap int return current line cap
int     setlinejoin - set shape of corners for stroke (0 = miter, 1 = round, 2 = bevel)
-     currentlinejoin int return current line join
num     setmiterlimit - set miter length limit
-     currentmiterlimit num return current miter limit
bool     setstrokeadjust - set stroke adjust (false = disable, true = enable)
-     currentstrokeadjust bool return current stroke adjust
array offset     setdash - set dash pattern for stroking
-     currentdash array offset return current dash pattern
array     setcolorspace - set color space
-     currentcolorspace array return current color space
comp1 ... compn     setcolor - set color components
-     currentcolor comp1 ... compn return current color components
num     setgray - set color space to DeviceGray and color to
specified gray value (0 = black, 1 = white)
-     currentgray num return current color as gray value
hue sat brt     sethsbcolor - set color space to DeviceRGB and color to
specified hue, saturation, brightness
-     currenthsbcolor hue sat brt return current color as hue, saturation, brightness
red green blue     setrgbcolor - set color space to DeviceRGB and color to specified red, green, blue
-     currentrgbcolor red green blue return current color as red, green, blue
cyan magenta yellow black     setcmykcolor - set color space to DeviceCMYK and color to specified cyan, magenta, yellow, black
-     currentcmykcolor cyan magenta yellow black return current color as cyan, magenta, yellow, black


Graphics State Operators - Device Dependent

dict     sethalftone - set halftone dictionary
-     currenthalftone dict return current halftone dictionary
frequency angle proc     setscreen - set gray halftone screen
-     currentscreen frequency angle proc return current gray halftone screen
redfreq redang redproc
greenfreq greenang greenproc
bluefreq blueang blueproc
grayfreq grayang grayproc
    setcolorscreen - set all four halftone screens
-     currentcolorscreen redfreq redang redproc
greenfreq greenang greenproc
bluefreq blueang blueproc
grayfreq grayang grayproc
return all four halftone screens
proc     settransfer - set gray transfer function
-     currenttransfer proc return current gray transfer function
redproc greenproc blueproc grayproc     setcolortransfer - set all four transfer functions
-     currentcolortransfer redproc greenproc blueproc grayproc return current transfer functions
proc     setblackgeneration - set black generation function
-     currentblackgeneration proc return current black generation function
proc     setundercolorremoval - set undercolor removal function
-     currentundercolorremoval proc return current undercolor removal function
dict     setcolorrendering - set CIE based color rendering dictionary
-     currentcolorrendering dict return current CIE based color rendering dictionary
num     setflat - set flatness tolerance
-     currentflat num return current flatness
bool     setoverprint - set overprint parameter
-     currentoverprint bool return current overprint parameter


Coordinate System and Matrix Operators

-     matrix matrix create identity matrix
-     initmatrix - set CTM to device default
matrix     identmatrix matrix fill matrix with identity transform
matrix     defaultmatrix matrix fill matrix with device default matrix
matrix     currentmatrix matrix fill matrix with CTM
matrix     setmatrix - replace CTM by matrix
tx ty     translate - translate user space by (tx ty)
tx ty matrix     translate matrix define translation by (tx ty)
sx sy     scale - scale user space by sx and sy
sx sy matrix     scale matrix define scaling by sx and sy
angle     rotate - rotate user space by angle degrees
angle matrix     rotate matrix define rotation by angle degrees
matrix     concat - replace CTM by matrix x CTM
matrix1 matrix2 matrix3     concatmatrix matrix3 fill matrix3 with matrix1 x matrix2
x y     transform x' y' transform (x, y) by CTM
x y matrix     transform x' y' transform (x, y) by matrix
dx dy     dtransform dx' dy' transform distance (dx, dy) by CTM
dx dy matrix     dtransform dx' dy' transform distance (dx, dy) by matrix
x' y'     itransform x y inverse transform (x', y') by CTM
x' y' matrix     itransform x y inverse transform (x', y') by matrix
dx' dy'     idtransform dx dy inverse transform distance (dx', dy') by CTM
dx' dy' matrix     idtransform dx dy inverse transform distance (dx', dy') by matrix
matrix1 matrix2     invertmatrix matrix2 fill matrix2 with inverse of matrix1


Path Construction Operators

-     newpath - initialize current path to be empty
-     currentpoint x y return current point coordinate
x y     moveto - set current point to (x, y)
dx dy     rmoveto - relative moveto
x y     lineto - append straight line to (x, y)
dx dy     rlineto - relative lineto
x y r ang1 ang2     arc - append counterclockwise arc
x y r ang1 ang2     arcn - append clockwise arc
x1 y1 x2 y2 r     arct - append tangent arc
x1 y1 x2 y2 r     arcto xt1 yt1 xt2 yt2 append tangent arc
x1 y1 x2 y2 x3 y3     curveto - append Bezier cubic section
dx1 dy1 dx2 dy2 dx3 dy3     rcurveto - relative curveto
-     closepath - connect subpath back to its starting point
-     flattenpath - convert curves to sequences of straight lines
-     reversepath - reverse direction of current path
-     strokepath - compute outline of stroked path
userpath     ustrokepath - compute outline of stroked userpath
serpath matrix     ustrokepath - compute outline of stroked userpath
string bool     charpath - append character outline to current path
userpath     uappend - interpret userpath and append to current path
-     clippath - set current path to clipping path
llx lly urx ury     setbbox - set bounding box for current path
-     pathbbox llx lly urx ury return bounding box of current path
move line curve close     pathforall - enumerate current path
bool     upath userpath create userpath for current path; include ucache if bool is true
-     initclip - set clipping path to device default
-     clip - clip using non-zero winding number rule
-     eoclip - clip using even-odd inside rule
x y width height     rectclip - clip with rectangular path
numarray | numstring     rectclip - clip with rectangular paths
-     ucache - declare that user path is to be cached


Painting Operators

-     erasepage - paint current page white
-     fill - fill current path with current color
-     eofill - fill using even-odd rule
-     stroke - draw line along current path
userpath     ufill - interpret and fill userpath
userpath     ueofill - fill userpath using even-odd rule
userpath     ustroke - interpret and stroke userpath
userpath matrix     ustroke - interpret userpath, concatenate matrix, and stroke
x y width height     rectfill - fill rectangular path
numarray | numstring     rectfill - fill rectangular paths
x y width height     rectstroke - stroke rectangular path
numarray | numstring     rectstroke - stroke rectangular paths
dict     image - paint any sampled image
width height bits/samp matrix datasrc     image - paint monochrome sampled image
width height bits/comp matrix
datasrc0 ... datasrcn-1 multi ncomp
    colorimage - paint color sampled image
dict     imagemask - paint current color through mask
width height polarity matrix datasrc     imagemask - paint current color through mask


Insideness Testing Operators

x y     infill boot test whether point (x, y) would be painted by fill
userpath     infill bool test whether pixels in userpath would be painted by fill
x y     ineofill bool test whether point (x, y) would be painted by eofill
userpath     ineofill bool test whether pixels in userpath would be painted by eofill
x y userpath     inufill bool test whether point (x, y) would be painted by ufill of userpath
userpath1 userpath2     inufill bool test whether pixels in userpath1 would be painted by inufill of userpath2
x y userpath     inueofill bool test whether point (x, y) would be painted by ueofill of userpath
userpath1 userpath2     inueofill bool test whether pixels in userpath1 would be painted by ueofill of userpath2
x y     instroke bool test whether point (x, y) would be painted by stroke
x y userpath     inustroke bool test whether point (x, y) would be painted by ustroke of userpath
x y userpath matrix     inustroke bool test whether point (x, y) would be painted by ustroke of userpath
userpath1 userpath2     inustroke bool test whether pixels in userpath1 would be painted by ustroke of userpath2
userpath1 userpath2 matrix     inustroke bool test whether pixels in userpath1 would be painted by ustroke of userpath2


Form and Pattern Operators

pattern matrix     makepattern pattern' create pattern instance from prototype
comp1 ... compn pattern     setpattern - install pattern as current color
form     execform - paint form


Device Setup and Output Operators

-     showpage - transmit and reset current page
-     copypage - transmit current page
dict     setpagedevice - install page-oriented output device
-     currentpagedevice dict return current page device parameters
-     nulldevice - install no-output device


Character and Font Operators

key font     definefont font register font as a font dictionary
key     undefinefont - remove font registration
key     findfont font return font dictionary identified by key
font scale     scalefont font' scale font by scale to produce new font'
font matrix     makefont font' transform font by matrix to produce new font'
font     setfont - set font dictionary in graphics state
-     currentfont font return current font dictionary
-     rootfont font return root composite font dictionary
key scale | matrix     selectfont - set font dictionary given name and transform
string     show - paint characters of string on page
ax ay string     ashow - add (ax ay) to width of each character while showing string
cx cy char string     widthshow - add (cx cy) to width of char while showing string
cx cy char ax ay string     awidthshow - combine effects of ashow and widthshow
string numarray | numstring     xshow - paint characters of string using x widths in numarray | numstring
string numarray | numstring     xyshow - paint characters of string using x and y widths in numarray | numstring
string numarray | numstring     yshow - paint characters of string using y widths in numarray | numstring
name     glyphshow - paint character identified by name
string     stringwidth wx wy width of string in current font
proc string     cshow - invoke show mapping algorithm and call proc
proc string     kshow - execute proc between characters shown from string
-     FontDirectory dict dictionary of font dictionaries
-     GlobalFontDirectory dict dictionary of font dictionaries in global VM
-     StandardEncoding array Adobe standard font encoding vector
-     ISOLatin1Encoding array international ISO Latin-1 font encoding vector
key     findencoding array find encoding array
wx wy llx lly urx ury     setcachedevice - declare cached character metrics
w0x w0y llx lly urx ury
w1x w1y vx vy
    setcachedevice2 - declare cached character metrics
wx wy     setcharwidth - declare uncached character metrics


Interpreter Parameter Operators

dict     setsystemparams - set system-wide interpreter parameters
-     currentsystemparams dict return system-wide interpreter parameters
dict     setuserparams - set per-context interpreter parameters
-     currentuserparams dict return per-context interpreter parameters
string dict     setdevparams - set parameters for input/output device
string     currentdevparams dict return device parameters
int     vmreclaim - control garbage collector
int     setvmthreshold - control garbage collector
-     vmstatus level used maximum report VM status
-     cachestatus bsize bmax msize mmax csize cmax blimit return font cache status and parameters
num     setcachelimit - set maximum bytes in cached character
mark size lower upper     setcacheparams - change font cache parameters
-     currentcacheparams mark size lower upper return current font cache parameters
mark blimit     setucacheparams - set user path cache parameters
-     ucachestatus mark bsize bmax rsize rmax blimit return user path cache status and parameters


Display PostScript Operators

-     currentcontext context return current context identifier
mark obj1 ... objn proc     fork context create context executing proc with obj1 ... objn as operands
context     join mark obj1 ... objn await context termination and return its results
context     detach - enable context to terminate immediately when done
-     lock lock create lock object
lock proc     monitor - execute proc while holding lock
-     condition condition create condition object
lock condition     wait - release lock, wait for condition, reacquire lock
condition     notify - resume contexts waiting for condition
-     yield - suspend current context momentarily
index name     defineusername - define encoded name index
-     viewclip - set view clip from current path
-     eoviewclip - set view clip using even-odd rule
x y width height     rectviewclip - set rectangular view clipping path
numarray | numstring     rectviewclip - set rectangular view clipping paths
-     initviewclip - reset view clip
-     viewclippath - set current path from view clip
-     deviceinfo dict return dictionary containing information about current device
-     wtranslation x y return translation from window origin to device space origin
x y     sethalftonephase - set halftone phase
-     currenthalftonephase x y return current halftone phase


Errors

      configurationerror   setpagedevice request cannot be satisfied
      dictfull   no more room in dictionary
      dictstackoverflow   too many begins
      dictstackunderflow   too many ends
      execstackoverflow   exec nesting too deep
      handleerror   called to report error information
      interrupt   external interrupt request (e.g., Control-C)
      invalidaccess   attempt to violate access attribute
      invalidcontext   improper use of context operation
      invalidexit   exit not in loop
      invalidfileaccess   unacceptable access string
      invalidfont   invalid font name or dictionary
      invalidid   invalid identifier for external object
      invalidrestore   improper restore
      ioerror   input/output error occurred
      limitcheck   implementation limit exceeded
      nocurrentpoint   current point is undefined
      rangecheck   operand out of bounds
      stackoverflow   operand stack overflow
      stackunderflow   operand stack underflow
      syntaxerror   PostScript language syntax error
      timeout   time limit exceeded
      typecheck   operand of wrong type
      undefined   name not known
      undefinedfilename   file not found
      undefinedresource   resource instance not found
      undefinedresult   over/underflow or meaningless result
      unmatchedmark   expected mark not on stack
      unregistered   internal error
      VMerror   VM exhausted