_ _ ___ | |__ __ _ _______ | |_ / _ \| '_ \ / _` |_ / _ \| __| | (_) | | | | (_| |/ / (_) | |_ \___/|_| |_|\__,_/___\___/ \__|
| ohazot | docs | links | dev | conf | txt |
| es | en |
| mdoc file |
| search |
postscript —
usage, macros, tips and examples.
PostScript is a stack-based documentation language.
BASICS
| 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 |
Example
%!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-Bold |
| Text in Helvetica |
Text in
Courier |
ps2pdf PS_FILE PDF_FILEBASIC MACROS
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
|
STACK
PostScript is a stack-based language, eg.: 2 3
add returns 5, 5 2 sub returns 3.
COMMANDS
| 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 |
Usage
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
- Define margin_left as 10
- Define line_height as 15
- Get current x and y
- Exchange x and y to have x as the top value in the stack.
- Pop x out of the stack.
- Remove line_height from current y position to get the new y position.
- new_line: Move to x at margin_left and cur_y
New text line
/text_line { new_line /Helvetica sel_font show } def
(line added with text_line) text_line
TODO
- Add sample file.
SEE ALSO
dc , latex , pdf , documentation
- Archlinux manpages: ps2pdf(1)
links
| - PLRM - PostScript Language Reference Manual |
| - PostScript Language Tutorial and Cookbook |
| - Thinking in PostScript |
| - A First Guide to PostScript |