Learning Foundations

Objects

1.4 §3.2–3.31.7 §7.3–7.4

The eight object types

TypeSyntaxNotes
Booleantrue false
Numeric42 -3 3.14 .5Integer and real. No exponent notation (1e5 is invalid).
String(Hello \(world\)) <48656C6C6F>Literal or hex. Bytes, not characters: interpretation depends on context (PDFDocEncoding, UTF-16BE with BOM, font encoding).
Name/Type /Font /A#20BAtoms used as keys and enum values. #xx escapes a byte (1.2+).
Array[0 0 612 792]Heterogeneous; may nest.
Dictionary<< /Type /Page /Rotate 90 >>Keys are names. A key with value null is the same as an absent key.
Stream<< /Length 41 >> stream … endstreamA dictionary followed by a byte sequence. Always an indirect object.
Nullnull

Read: 1.4 §3.21.7 §7.3

Indirect objects and references

Any object can be given an identity, an object number plus a generation number, and then referred to from anywhere:

12 0 obj                 % define object 12, generation 0
<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>
endobj

<< /Font << /F1 12 0 R >> >>  % "12 0 R" = reference to that object

The generation number only increases when an object number is freed and reused. In practice it is almost always 0.

Streams and filters

Streams hold the bulk data: page content, images, fonts, metadata. /Filter names the encoding to undo, and filters can be chained ([/ASCII85Decode /FlateDecode]), applied in order when decoding.

4 0 obj
<< /Length 1532 /Filter /FlateDecode >>
stream
…1532 bytes of zlib data…
endstream
endobj
FilterUseSince
FlateDecodezlib/deflate; the default for almost everything. Supports PNG predictors via /DecodeParms.1.2
DCTDecodeBaseline JPEG images1.0
CCITTFaxDecodeGroup 3/4 fax, bilevel scans1.0
JBIG2DecodeBetter bilevel compression1.4
JPXDecodeJPEG 20001.5
CryptPer-stream crypt filter selection1.5
ASCIIHexDecode, ASCII85Decode, LZWDecode, RunLengthDecodeLegacy and 7-bit-safe encodings1.0

The Filters reference has every filter with its parameters.

Read: 1.4 §3.31.7 §7.4

Gotcha: /Length may itself be an indirect reference (/Length 7 0 R), because a writer streaming output doesn't know the length until it has written the data. Robust parsers also cope with a wrong /Length by scanning for endstream.
Q1. Which of these is not a valid PDF number?
.5-31e53.14
Check
Q2. A stream has /Filter [/ASCII85Decode /FlateDecode]. In what order does a reader decode it?
ASCII85 first, then FlateFlate first, then ASCII85Either order gives the same bytesOnly the last filter applies
Check
Q3. Why may a stream's /Length be an indirect reference such as 7 0 R?
So several streams can share one lengthBecause lengths over 65535 must be indirectSo that encryption can change itBecause a writer streaming its output doesn't know the length until it has written the data
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.