A page's /Contents is a stream of postfix instructions: operands first, then the operator. No variables, loops or procedures. Names like /F1 or /Im0 are looked up in the page's /Resources.
q % save graphics state 1 0 0 rg % fill color: red (DeviceRGB) 72 600 200 100 re f % rectangle at (72,600), 200×100, fill Q % restore state 0 0 1 RG 4 w % stroke color blue, line width 4 72 550 m 272 550 l S % move, line, stroke q 200 0 0 150 300 400 cm % scale and translate the unit square /Im0 Do Q % paint image XObject Im0 into it BT /F1 18 Tf 72 500 Td (Text!) Tj ET
Coordinates
The origin is the bottom-left and y grows upward. The current transformation matrix (CTM) maps user space to device space; a b c d e f cm concatenates a matrix onto it. Scale is sx 0 0 sy 0 0 cm, translate is 1 0 0 1 tx ty cm. Images always paint into the unit square, so you cm to size them.
Operator cheat sheet
Every operator, grouped. The Operators reference has each one's operands and the rules for where it may appear.
| Group | Operators |
|---|---|
| Graphics state | q Q save/restore; cm matrix; w J j M d line width/cap/join/miter/dash; ri intent; i flatness; gs apply ExtGState |
| Path construction | m move; l line; c v y Béziers; h close; re rectangle |
| Path painting | S s stroke; f F f* fill (nonzero / even-odd; F is an obsolete synonym for f); B B* b b* fill+stroke; n no-op end |
| Clipping | W W*, takes effect at the next painting operator (usually n) |
| Color | CS cs set space; SC SCN sc scn set color; G g gray; RG rg RGB; K k CMYK. Upper case = stroke, lower case = fill. |
| XObjects & images | Do paint image or form XObject; BI ID EI inline image; sh shading |
| Text | BT ET; Tf Tc Tw Tz TL Tr Ts state; Td TD Tm T* position; Tj TJ ' " show |
| Type 3 fonts | d0 d1 set a glyph's width (and bounding box); only at the start of a glyph in a Type 3 font's /CharProcs |
| Marked content | BMC BDC EMC MP DP, which tag content for structure and layers |
| Compatibility | BX EX, inside which unknown operators are ignored |
Operators:
Resources and XObjects
Sub-dictionaries keyed by category:
/Font /XObject /ExtGState /ColorSpace /Pattern /Shading /Properties. The legacy /ProcSet is ignored by modern readers.A stream with
/Width /Height /BitsPerComponent /ColorSpace, plus optional /SMask, a soft-mask image for alpha (1.4).A reusable mini content stream with its own
/BBox, /Matrix and resources. Used for repeated graphics, annotation appearances and transparency groups.Color spaces
Device: DeviceGray, DeviceRGB, DeviceCMYK. CIE-based: CalGray, CalRGB, Lab, ICCBased. Special: Indexed, Pattern, Separation (spot inks), DeviceN (multiple inks; the NChannel subtype was added in 1.6). Output intents (1.4) say which printing condition the file targets, which is central to PDF/X and PDF/A. The Color spaces reference has each family with its parameters and initial color.