Learning Foundations

The document tree

1.4 §3.61.7 §7.7

trailer
 └─ /Root → Catalog            /Type /Catalog
     ├─ /Pages → Page tree     /Type /Pages  /Kids [...]  /Count N
     │    ├─ Page              /Type /Page   /Contents  /Resources  /MediaBox
     │    └─ Pages (subtree)   intermediate nodes keep large trees balanced
     ├─ /Outlines              bookmarks
     ├─ /Names                 name trees: /Dests, /EmbeddedFiles, /JavaScript …
     ├─ /AcroForm              interactive form fields
     ├─ /Metadata              XMP stream (1.4)
     ├─ /StructTreeRoot        logical structure (1.3), Tagged PDF (1.4)
     ├─ /MarkInfo              << /Marked true >> for Tagged PDF (1.4)
     ├─ /Lang                  default natural language (1.4)
     ├─ /Version               overrides the header version (1.4)
     ├─ /OCProperties          optional content / layers (1.5)
     └─ /Collection            portable collection / portfolio (1.7)

Read: 1.4 §3.61.7 §7.7.2 Catalog1.7 §7.7.3 Page tree

Where the tree lives in the file

The tree above is logical, not physical. Nothing in the file is laid out as an indented tree. The objects are just numbered indirect objects (5 0 obj … endobj), written to the body in any order, and the "tree" is the graph you get by following their N 0 R references.

A reader reconstructs it from the bottom of the file upward:

  • The trailer gives /Root → the catalog's object number, e.g. /Root 1 0 R.
  • The cross-reference table (or xref stream) maps that object number to a byte offset, so the reader seeks straight to 1 0 obj.
  • From the catalog it follows /Pages, then each /Kids entry, resolving every N 0 R through the xref the same way.

So the root is the trailer's /Root, the links are indirect references, and the xref is the index that turns a reference into a file position. The File anatomy page shows this on a real 6-object file.

Page attributes and inheritance

Four page attributes are inheritable: /Resources, /MediaBox, /CropBox and /Rotate. If a page doesn't have one, walk up /Parent links until a /Pages node does. Forgetting this is the most common bug in hand-written PDF readers.

Page boundaries

BoxMeaning
MediaBoxThe physical medium. Required (directly or inherited). Default user space is 1/72 inch, so US Letter is [0 0 612 792].
CropBoxVisible region when displayed or printed. Defaults to MediaBox.
BleedBox, TrimBox, ArtBoxProduction boxes: bleed area, finished size, meaningful content. Defined in 1.3; display and preview support documented in 1.4.

1.6 added /UserUnit to scale the 1/72-inch unit for very large pages.

Other structures you'll meet

Name trees and number trees
Sorted key→value maps split into balanced nodes (/Kids, /Names, /Limits). Used for named destinations, embedded files, page labels and more.
Outlines
A doubly-linked tree of bookmark items (/First /Last /Next /Prev /Parent), each with a /Title and a destination or action. 1.4 added /C color and /F style flags.
Destinations
[pageRef /XYZ left top zoom], /Fit, /FitH…, either inline or by name via /Dests.
Dates and text strings
Dates look like (D:20011103142300+01'00'). Text strings are PDFDocEncoding or UTF-16BE starting with the BOM FE FF.
Q1. How is the document tree laid out in the file?
As nested dictionaries, indented like the treeCatalog first, then the page tree in order, then the pagesAs numbered objects in any order, linked by N 0 R referencesIn a separate section after the cross-reference table
Check
Q2. Which of these page attributes is not inherited from a /Pages node?
/MediaBox/Rotate/Resources/Contents
Check
Q3. A 1.3 file is edited with an incremental update that uses 1.4 features. Where does the new version number go?
Rewrite the %PDF- headerThe /Version entry in the catalogThe trailer's /Info dictionaryA new startxref comment
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.