PDF draws with the imaging model of PostScript: paths, text and images painted in
order, each over what is already there, through a clipping path, in a colour space.
PDF 1.4 added transparency, so that what is painted can blend with what is beneath.
PDF 1.5 to 2.0 keep this model and add to it: UserUnit and NChannel
colour in 1.6, black point compensation and page-level output intents in 2.0. The
content stream
operators drive it all.
Coordinate spaces
| Space | What it is |
|---|---|
| Device space | The pixels or dots of the screen or printer. A file never uses it directly |
| User space | The page’s own coordinates. By default one unit is 1/72 inch, the x axis goes right and the y axis up, from the bottom left of the MediaBox |
| Current transformation matrix (CTM) | Maps user space to device space. cm changes it; q and Q save and restore it |
| Text space | Set by the text matrix (Tm, Td) inside a text object, with the font size and horizontal scaling |
| Glyph space | A font’s own units: 1,000 to the text space unit for most fonts; set by FontMatrix for Type 3 |
| Image space | An image is always painted into the unit square, 0 to 1 on both axes, so the CTM sets its size and place |
| Form space | A form XObject’s coordinates, mapped by its Matrix |
| Pattern space | A pattern’s coordinates, mapped by its Matrix from the default space of the page (or form) it is used in, not from the CTM at the moment of use |
A matrix is six numbers [a b c d e f], standing for the 3 × 3 matrix
with rows a b 0, c d 0 and e f 1. A point
(x, y) goes to (ax + cy + e,
bx + dy + f). Rotation by θ is
[cos θ sin θ −sin θ cos θ 0 0].
From PDF 1.6 a page can set UserUnit, the size of a default user space
unit in multiples of 1/72 inch. Acrobat limits a page to 14,400 units, 200 inches
at the default size; with UserUnit 10 the same page box covers ten
times as much, for maps and banners. The page’s Rotate turns the whole of user space when it is
shown.
Colour spaces
A colour space is a name, for the device spaces and Pattern, or an array
whose first element is the family name. It is set with CS or
cs, or given to an image, a shading or a group.
| Family | Since | Components | Written as |
|---|---|---|---|
DeviceGray | 1.0 | 1, 0 black to 1 white | /DeviceGray |
DeviceRGB | 1.0 | 3, each 0 to 1 | /DeviceRGB |
DeviceCMYK | 1.0 | 4, each 0 to 1 | /DeviceCMYK |
CalGray | 1.1 | 1 | [/CalGray << /WhitePoint [..] /BlackPoint [..] /Gamma g >>] |
CalRGB | 1.1 | 3 | [/CalRGB << /WhitePoint /BlackPoint /Gamma [3] /Matrix [9] >>] |
Lab | 1.1 | 3, L* 0 to 100, a* and b* in Range | [/Lab << /WhitePoint /BlackPoint /Range [−100 100 −100 100] >>] |
ICCBased | 1.3 | N: 1, 3 or 4 | [/ICCBased stream]; the stream is an ICC profile, with N required and Alternate, Range and Metadata |
Indexed | 1.0 | 1, an index 0 to hival | [/Indexed base hival lookup]; lookup is a string or stream of (hival + 1) × the base’s components bytes |
Pattern | 1.2 | none, or the underlying space’s for an uncoloured pattern | /Pattern or [/Pattern base] |
Separation | 1.2 | 1, a tint 0 to 1 | [/Separation name alternateSpace tintTransform] |
DeviceN | 1.3 | one for each name | [/DeviceN names alternateSpace tintTransform attributes] |
- The
WhitePointof the CIE-based spaces is required, as CIE XYZ with Y = 1;BlackPointdefaults to[0 0 0]. - A
SeparationorDeviceNcolourant is a named ink, such as/PANTONE#20185#20C;Allmeans every colourant, andNonepaints nothing. When the device has no such ink, the tint transform, a function, converts the tints to the alternate space. - The
DeviceNattributes dictionary hasSubtype(DeviceN, orNChannelfrom 1.6, which says that the colourants are described for blending),Colorants(Separation spaces for spot colourants),Process(the process colour space and its components) andMixingHints. - The initial colour is black in the device and CIE-based spaces, the index 0 in
Indexed, and a tint of 1.0 inSeparationandDeviceN. - A page or group can set
DefaultGray,DefaultRGBandDefaultCMYKin itsColorSpaceresources to replace the device spaces with calibrated ones.
Patterns
A pattern paints an area with something other than a flat colour. It is selected by
setting the Pattern colour space and giving its name to
scn or SCN: /Pattern cs /P1 scn.
| PatternType | Since | Kind | Keys |
|---|---|---|---|
| 1 | 1.2 | Tiling: a small content stream repeated across the area | A stream with PaintType (1 coloured, 2 uncoloured: the colour comes from scn), TilingType (1 constant spacing, 2 no distortion, 3 faster), BBox, XStep, YStep, Resources, Matrix |
| 2 | 1.3 | Shading: a smooth colour change | A dictionary with Shading, Matrix and ExtGState |
Shadings
A shading, from PDF 1.3, is a smooth change of colour. It is painted either as a
shading pattern, or directly with sh over the current clip. Every shading
has ShadingType, ColorSpace (required), and may have
Background, BBox and AntiAlias.
| Type | Name | Keys of its own |
|---|---|---|
| 1 | Function-based | Domain (default [0 1 0 1]), Matrix, Function of x and y |
| 2 | Axial: along a line | Coords [x0 y0 x1 y1], Domain (default [0 1]), Function of t, Extend [false false] |
| 3 | Radial: between two circles | Coords [x0 y0 r0 x1 y1 r1], Domain, Function, Extend |
| 4 | Free-form Gouraud triangle mesh | A stream of vertices: BitsPerCoordinate, BitsPerComponent, BitsPerFlag, Decode, Function. Each vertex is a flag, x, y and colour; the flag says how it joins the triangle before |
| 5 | Lattice-form Gouraud triangle mesh | A stream of rows of vertices: BitsPerCoordinate, BitsPerComponent, VerticesPerRow, Decode, Function |
| 6 | Coons patch mesh | A stream of patches of 12 control points (four Bézier sides) and four corner colours; keys as type 4 |
| 7 | Tensor-product patch mesh | As type 6, with 16 control points a patch |
In the mesh types the coordinates and colours are packed integers, read
most-significant bit first and mapped through Decode to real values. When
Function is given, each vertex has one colour component, t, which the
function turns into a colour.
Functions
Functions map one or more inputs to outputs. Shadings, tint transforms, transfer
functions, halftone spot functions and soft masks use them. Each has
FunctionType, Domain (required, input ranges) and
Range (output ranges, required for types 0 and 4). Inputs and outputs are
clipped to them.
| Type | Since | Name | Keys |
|---|---|---|---|
| 0 | 1.2 | Sampled: a table of values, interpolated | A stream: Size, BitsPerSample (1, 2, 4, 8, 12, 16, 24 or 32), Order (1 linear, 3 cubic), Encode, Decode |
| 2 | 1.3 | Exponential: C0 + xN × (C1 − C0) | C0 (default [0]), C1 (default [1]), N |
| 3 | 1.3 | Stitching: several one-input functions side by side | Functions, Bounds, Encode |
| 4 | 1.3 | PostScript calculator: a small program | A stream of PostScript in braces, such as { 2 exch sub }, using only arithmetic, comparison, boolean, if, ifelse and stack operators |
The graphics state and ExtGState
Some graphics state parameters can be set only from a graphics state parameter
dictionary, named in the ExtGState resources and applied with
gs:
| Key | Since | Sets |
|---|---|---|
Type | 1.2 | ExtGState |
LW, LC, LJ, ML, D | 1.3 | Line width, cap, join, mitre limit, dash pattern, as w J j M d |
RI | 1.3 | Rendering intent, as ri |
OP | 1.2 | Overprint for stroking (and for everything, if there is no op) |
op | 1.3 | Overprint for non-stroking |
OPM | 1.3 | Overprint mode, 0 or 1: whether zero CMYK components leave the ink beneath |
Font | 1.3 | An array of a font and a size, as Tf |
BG, BG2 | 1.2, 1.3 | Black generation function |
UCR, UCR2 | 1.2, 1.3 | Undercolour removal function |
TR, TR2 | 1.2, 1.3 | Transfer functions. 2.0 deprecated |
HT | 1.2 | Halftone |
FL | 1.3 | Flatness, as i |
SM | 1.3 | Smoothness tolerance for shadings |
SA | 1.2 | Automatic stroke adjustment |
BM | 1.4 | Blend mode |
SMask | 1.4 | Soft mask, or None |
CA, ca | 1.4 | Constant alpha for stroking and non-stroking, 0 to 1 |
AIS | 1.4 | Alpha source: whether the soft mask and alpha are shape rather than opacity |
TK | 1.4 | Text knockout |
UseBlackPtComp | 2.0 | Black point compensation: ON, OFF or Default |
HTO | 2.0 | Halftone origin, in device space |
Black point compensation, from PDF 2.0, adjusts colour conversion so that the darkest colour of the source maps to the darkest of the destination, keeping detail in shadows. Before PDF 2.0 it was left to the reader.
Halftones
A halftone says how a printer turns grey levels into dots. Types 1 (a screen with a frequency, angle and spot function), 5 (one halftone a colourant), 6 (a threshold array), 10 (an angled threshold array) are from PDF 1.2, and 16 (16-bit thresholds) from 1.3. Screens only matter on printing devices; viewers ignore them.
Transparency
From PDF 1.4 each object painted is blended with the backdrop beneath. Three things take part: the blend mode, the shape and the opacity.
Blend modes
Separable modes, applied to each colour component:
Normal (default), Multiply, Screen,
Overlay, Darken, Lighten,
ColorDodge, ColorBurn, HardLight,
SoftLight, Difference and Exclusion.
Non-separable modes, applied to the colour as a whole: Hue,
Saturation, Color and Luminosity.
Compatible is the same as Normal and should not be
written. BM may be an array of modes, of which the reader uses the
first it knows; PDF 2.0 deprecates the array form.
Soft masks
A soft mask gives varying opacity or shape across an area. In a graphics state it
is a dictionary of Type Mask with S (Alpha:
the group’s alpha is the mask; Luminosity: its luminosity is),
G, a transparency group form XObject that draws the mask,
BC, the backdrop colour for Luminosity, and
TR, a transfer function. An image can carry its own soft mask in
SMask; see Images.
Transparency groups
A form XObject, or a page, with a Group dictionary of
S Transparency is composited as a unit before it is blended with what
is beneath. Its keys are CS, the blending colour space;
I, isolated (true: blend inside the group starts from a transparent
backdrop, not what is beneath); and K, knockout (true: each object in
the group blends with the group’s initial backdrop, not with the objects before it
in the group). A page group sets the colour space in which a viewer composites the
page.
Form XObjects
A form XObject is a content stream that can be drawn many times, with
Do, as a reusable piece of a page, an annotation appearance, a pattern
cell or a transparency group.
| Key | Since | Meaning |
|---|---|---|
Type, Subtype | 1.0 | XObject and Form (required) |
FormType | 1.0 | 1, the only value |
BBox | 1.0 | Required. The form’s bounding box in form space; it clips the form |
Matrix | 1.0 | Maps form space to the user space where it is drawn; default the identity |
Resources | 1.2 | The form’s own resources. Older files leave them out and use the page’s; PDF 2.0 requires them |
Group | 1.4 | Makes it a transparency group |
Ref | 1.4 | A reference XObject: the content is a page of another PDF file |
Metadata | 1.4 | XMP metadata |
PieceInfo, LastModified | 1.3 | Private data of programs, and when it changed |
StructParent, StructParents | 1.3 | Keys in the structure parent tree |
OPI | 1.2 | Open Prepress Interface proxy information. 2.0 deprecated |
OC | 1.5 | The optional content the form belongs to |
Name | 1.0 | The resource name. 2.0 deprecated |
AF, Measure, PtData | 2.0 | Associated files, and geospatial measurement and point data (earlier as Adobe’s extension level 3) |