paulgorman.org/technical

Postscript

Postscript is a page description and programming language.

gv can view postscript files, and also provides useful ps tools.

Hello, world

hello.ps:

%!PS-Adobe-3.0

%%Pages: 2
%%DocumentData: Clean7Bit
%%LanguageLevel: 3
%%DocumentMedia: Letter 612 792 0 () ()
%%Page: 1 1
%%BeginPageSetup
%%PageOrientation: Portrait
%%EndPageSetup
/Times-Bold findfont
30 scalefont
setfont
100 300 moveto
(Hello, world! Page 1) show
showpage
%%Page: 2 2
%%BeginPageSetup
%%PageOrientation: Portrait
%%EndPageSetup
/Times-Bold findfont
30 scalefont
setfont
100 300 moveto
(Hello, world! Page 2) show
showpage
%%EOF

Coordinates are measured in points, and originate from the bottom left of the page.

Note that the blank line after the header is required.

Including An Image

(I ripped the image data out of a ps I saved out of Gimp.)

hello-img.ps:

%!PS-Adobe-3.0

%%Pages: 1
%%DocumentData: Clean7Bit
%%LanguageLevel: 3
%%DocumentMedia: Letter 612 792 0 () ()
%%Page: 1 1
%%BeginPageSetup
%%PageOrientation: Portrait
%%EndPageSetup
/Times-Bold findfont
30 scalefont
setfont
200 300 moveto
(Hello, world!) show
% Translate for offset
100 100 translate
% Translate to begin of first scanline
0 67.679999999999993 translate
46.799999999999997 -67.679999999999993 scale
% Image geometry
65 94 8
% Transformation matrix
[ 65 0 0 94 0 0 ]
currentfile /ASCII85Decode filter /RunLengthDecode filter
%%BeginData:         1551 ASCII Bytes
image
hZ*?Nm/Q_XquH6dp]0jaquHWpq>^<lnc/@anc/LequHQmqZ-0dp]0jaquHWpq>^<lnc/@anc/Le
quHQmq>g*dq#KpaquHToqZ$BlgAh$MqZ-HlqZ,@MqZ-Knq>^<lgAh$MqZ-EkquGINqZ$WrquHNl
quH6dquH6dqZ$WrquHNlquH6dquH9eqZ$Wr!<;rsq#C6lnGiCdnc/Id!<3'!mJubVquH9eqZ$Wr
!<;Ednc/Lenc/Id!<3'!m/Z\VquH9eqZ$Wr!<;Ednc/Lenc/Id!<3'!m/Z\VquH9eqZ$Wr!<;rs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ZpiW&NMp](0kquGaVo`4[br;ZZpj8\fQoDeagquGgXpAja`r;ZZp
jo>&TnGiFdqZ,gZpAj[^r;ZWokPt;Wmf34bqZ,j[p]0^]r;ZTnlMpVZm/R"`q>fg\q#Ka\qu?Km
m/Qk]lMpb]q#Kg^q#K^[qZ$BlmJm"_l2UV[q>fp_qZ,j[qZ$BlmJm%`kl:JYqZ-$`quGp[q#C6l
mJm(akPt>WquH-aquGp[J,~>
%%EndData
showpage
%%EOF

http://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF http://paulbourke.net/dataformats/postscript/ http://www.physics.emory.edu/faculty/weeks//graphics/howtops1.html http://www.tailrecursive.org/postscript/postscript.html