Learning Drawing a page

Content streams

1.4 §3.7, ch. 41.7 §7.8, §8

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.

GroupOperators
Graphics stateq Q save/restore; cm matrix; w J j M d line width/cap/join/miter/dash; ri intent; i flatness; gs apply ExtGState
Path constructionm move; l line; c v y Béziers; h close; re rectangle
Path paintingS 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
ClippingW W*, takes effect at the next painting operator (usually n)
ColorCS 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 & imagesDo paint image or form XObject; BI ID EI inline image; sh shading
TextBT ET; Tf Tc Tw Tz TL Tr Ts state; Td TD Tm T* position; Tj TJ ' " show
Type 3 fontsd0 d1 set a glyph's width (and bounding box); only at the start of a glyph in a Type 3 font's /CharProcs
Marked contentBMC BDC EMC MP DP, which tag content for structure and layers
CompatibilityBX EX, inside which unknown operators are ignored

Operators: 1.4 App. A1.7 Annex A Graphics: 1.4 ch. 41.7 §8

Resources and XObjects

Resource dictionary
Sub-dictionaries keyed by category: /Font /XObject /ExtGState /ColorSpace /Pattern /Shading /Properties. The legacy /ProcSet is ignored by modern readers.
Image XObject
A stream with /Width /Height /BitsPerComponent /ColorSpace, plus optional /SMask, a soft-mask image for alpha (1.4).
Form XObject
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.

Q1. In default user space, where is the origin and what is one unit?
Top-left, 1 pixelBottom-left, 1/72 inchTop-left, 1/72 inchCenter, 1 mm
Check
Q2. What does 0 0 1 RG set?
The fill color, to blueThe stroke color, to blueBoth stroke and fill, to blueThe stroke color, to red
Check
Q3. An image is painted with /Im0 Do. What decides its size on the page?
Its /Width and /Height, read as pointsThe page's /MediaBoxThe current transformation matrix: images always paint into the unit squareThe image's own /BBox
Check
Reset3 questions

Section references such as 1.4 §3.4 1.7 §7.5 are to the Adobe PDF Reference, third edition (PDF 1.4) and ISO 32000-1:2008 (PDF 1.7). Where to get them: PDF specifications.