_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

postscriptusage, macros, tips and examples. PostScript is a stack-based documentation language.

Document processor : %!PS or %!PS-Adobe
Using %!Ps-Adobe allows PDF viewers to show document properties.
Tested properties: %%Title , %%Creator
Device parameters : setpagedevice
Example:
/PageSize
<< /PageSize [ width height ] >> setpagedevice
Set position : x y moveto
position 0 0 moveto is bottom left.
Set font : /fontName fontSize selectfont
Fonts tested: Helvetica, Courier, Times, Palatino.
All tested fonts have variants: -Bold, -Oblique, -BoldOblique. Eg.: /Helvetica-Bold
Display text : (Text) show
Show content : showpage

%!PS-Adobe
%%Title: The practice document
%%Creator: the ps creator
<< /PageSize [792 612] >> setpagedevice
10 580 moveto
/Helvetica-Bold 12 selectfont
(Text in Helvetica-Bold) show
10 560 moveto
/Helvetica 12 selectfont
(Text in Helvetica) show
10 545 moveto
/Courier 12 selectfont
(Text in Courier) show
showpage

Text in Helvetica
The example can be saved and exported to PDF:
ps2pdf PS_FILE PDF_FILE

back to top

Macros are defined as /MacroName MacroContent def or /MacroName { MacroContent } def .

Store page size:
/pageWidth 792 def
/pageHeight 612 def
<< /PageSize [pageWidth PageHeight] >> setpagedevice
Letter is 612x792, A4 is 595x843, can be inverted to use in portrait or landscape.
selectfont function:
/fontSize 12 def
/selFont { fontSize selectfont } def
/font /Helvetica selFont def
selFont

back to top

PostScript is a stack-based language, eg.: 2 3 add returns 5, 5 2 sub returns 3.

back to top

Return current x and y : currentpoint
Exchange the top two values from the stack : exch
Return the top value from the stack : pop
Sum top two values : add
Sub top value from previous value : sub
Multiply top two values : mul
Divide the previous to last value by the top value : div

Set new y position

/margin_left 10 def
/line_height 15 def
/cur_y { currentpoint exch pop line_height sub } def
/new_line { margin_left cur_y moveto } def
  1. Define margin_left as 10
  2. Define line_height as 15
  3. Get current x and y
  4. Exchange x and y to have x as the top value in the stack.
  5. Pop x out of the stack.
  6. Remove line_height from current y position to get the new y position.
  7. new_line: Move to x at margin_left and cur_y

/text_line { new_line /Helvetica sel_font show } def
(line added with text_line) text_line

back to top

back to top

dc , latex , pdf , documentation

- Archlinux manpages: ps2pdf(1)

- PLRM - PostScript Language Reference Manual
- PostScript Language Tutorial and Cookbook
- Thinking in PostScript
- A First Guide to PostScript

back to top

ohazot | about | ohazot.com <admin@ohazot.com>

This document applies to: linux , OpenBSD 7.8 | Created:2026-03-30|Updated:2026-03-30|