Learning Beyond the page

Tagged PDF and metadata

1.4 §9.2, 9.6–9.81.7 §14.3, 14.7–14.9

1.3 introduced logical structure; 1.4 standardized it as Tagged PDF, which gives a document reading order and semantics (headings, paragraphs, tables, figures with alt text) independent of how it is drawn.

% Catalog
/MarkInfo << /Marked true >>  /StructTreeRoot 20 0 R  /Lang (en-US)

% Page content: mark a run with a marked-content ID
/P << /MCID 0 >> BDC
  BT /F1 12 Tf 72 700 Td (Hello) Tj ET
EMC

% Structure element pointing at it
21 0 obj << /Type /StructElem /S /P /P 20 0 R /Pg 3 0 R /K 0 >> endobj
  • Standard structure types: Document Part Sect Div H H1–H6 P L LI Table TR TH TD Figure Caption Link Span… with /RoleMap for custom names. The Structure types reference lists them all.
  • Accessibility: /Alt (alt text), /ActualText (replacement text), /E (expansion of abbreviations, 1.5), /Lang.
  • PDF/UA-1 (ISO 14289-1) is the accessibility profile built on 1.7. Well-Tagged PDF (WTPDF 1.0) is the 2.0-era successor guidance.

Read: 1.4 §9.6–9.71.7 §14.7–14.8

Three things that make a PDF "tagged"

The flag
/MarkInfo << /Marked true >> in the catalog declares that the file follows Tagged PDF conventions. Without it, readers treat any structure as a hint.
The structure tree
/StructTreeRoot in the catalog: a tree of structure elements (Document → H1, P, Table…) in logical reading order.
Marked content
Every piece of page content is either wrapped in BDC … EMC with an /MCID that a structure element claims, or marked as an /Artifact.

Structure tree dictionaries

DictionaryKeyMeaning
/StructTreeRoot/KTop-level element(s), usually one /Document element.
/ParentTreeNumber tree mapping page and object keys back to structure elements. Required if any element has content.
/ParentTreeNextKeyNext free key in the parent tree, for writers adding pages.
/RoleMapMaps custom structure types to standard ones, e.g. /Heading1 /H1.
/IDTree, /ClassMapElement ids, and named attribute classes shared by many elements.
/StructElem/SStructure type (/P, /H1, /Figure…). Required.
/PParent element. Required, indirect reference.
/KChildren: MCIDs, references and nested elements (below).
/PgDefault page for integer MCIDs in /K.
/A, /CLayout and table attributes, inline or by class name.
/Alt, /ActualText, /Lang, /E, /T, /IDAccessibility text, language, title, element id.

How the pieces link up

Links run in both directions. Down the tree, so a screen reader can walk the document in reading order; and back up from the page, so a viewer can find which element owns the text under your cursor.

  DOWN  (reading order)                         UP  (content → element)

  Catalog                                       Page 3 0 obj
   └─ /StructTreeRoot 20 0 R                     └─ /StructParents 0
       └─ /K [21 0 R …]                               │
           └─ StructElem 21 0 obj                     ▼
               /S /P   /Pg 3 0 R   /K 0         StructTreeRoot /ParentTree
                                    │            /Nums [ 0 [21 0 R …] ]
                                    ▼                       │
  Page 3 content stream:                                    ▼
   /P << /MCID 0 >> BDC … EMC  ◀─────────────  index 0 of that array = MCID 0

The page's /StructParents is a key into the parent tree; the value stored there is an array indexed by MCID. Annotations and form XObjects that belong to the structure use the singular /StructParent, whose parent-tree value is a single element.

The two directions must agree. A /K that claims an MCID the parent tree doesn't map back (or the reverse) is the most common tagging defect, and PDF/UA validators reject it.

What /MCID does

A marked-content identifier is the glue between a structure element and the marks it describes. In the content stream, /P << /MCID 0 >> BDC … EMC labels a run of operators with the integer 0. The structure element then points back at that run.

  • MCIDs are numbered per page, starting at 0, and must be unique within a page's content stream.
  • The page's /StructParents entry keys into the structure tree's /ParentTree (a number tree), which maps each MCID back to its owning structure element, the reverse of the /K link below.
  • The marked-content tag before BDC (here /P) is a hint; the real semantics come from the structure element's /S (structure type).

What /K means here

In a structure element, /K ("kids") is what the element contains, and its form depends on the value:

  • an integer is an MCID on the element's page (/Pg): /K 0 means "the content marked /MCID 0".
  • an object reference to another structure element nests the tree.
  • a marked-content reference or object reference dictionary targets content on a different page, or an annotation / XObject.
  • an array mixes any of the above, for an element with several children.
/K is overloaded across PDF. This structure-element /K is unrelated to the knockout /K true in a transparency group, to the K content-stream operator (CMYK stroke color), or to /K in CCITTFaxDecode parameters. Read it by the dictionary it sits in.
% Element whose content spans two pages, plus a link annotation
22 0 obj
<< /Type /StructElem /S /Link /P 21 0 R /Pg 3 0 R
   /K [ 1                                              % MCID 1 on page 3 (/Pg)
        << /Type /MCR /Pg 4 0 R /MCID 0 >>             % MCID 0 on page 4
        << /Type /OBJR /Obj 30 0 R >> ] >>            % the link annotation itself
endobj

Artifacts: content that isn't content

Running headers, page numbers, rules and backgrounds are artifacts: they're drawn, but they aren't part of what the author wrote, so they must not appear in the structure tree or a screen reader would announce "Page 7" in the middle of a sentence. Mark them in the content stream instead:

/Artifact << /Type /Pagination /Subtype /Footer >> BDC
  BT /F1 9 Tf 290 30 Td (7) Tj ET
EMC

/Artifact BMC   % no property list: allowed, but property lists help reflow
  0.5 w 72 60 m 540 60 l S
EMC
/TypeFor
/PaginationRunning heads, folios. In 1.7, /Subtype can say /Header, /Footer or /Watermark.
/LayoutCosmetic design: footnote rules, decorative borders.
/PageProduction aids such as cut marks and color bars.
/BackgroundFull-page or full-element backgrounds (1.7); needs /BBox.

The rule a validator checks: every drawing operation on a page is either inside marked content that a structure element owns, or inside an artifact. Nothing is left untagged.

Read: 1.4 §9.7.21.7 §14.8.2.2

Metadata

Two places, which should agree:

  • Document information dictionary, the trailer's /Info: /Title /Author /Subject /Keywords /Creator /Producer /CreationDate /ModDate. Present since 1.0 and deprecated in 2.0.
  • XMP metadata stream (1.4): /Metadata on the catalog, a stream with /Type /Metadata /Subtype /XML holding RDF/XML. Required by PDF/A. Can also be attached to pages, images and fonts.

Read: 1.4 §9.21.7 §14.3

Q1. What in the catalog declares that a file follows Tagged PDF conventions?
/StructTreeRoot/MarkInfo << /Marked true >>/Lang/Metadata
Check
Q2. In a structure element, what does /K 0 mean?
Knockout is offThe element has no childrenThe content marked /MCID 0 on the element's page (/Pg)The element's first child in the parent tree
Check
Q3. How does a viewer find which structure element owns the text under the cursor?
It searches the structure tree from the rootFrom the page's /StructParents, through the /ParentTree, to the entry for that MCIDThrough the font's /ToUnicode CMapFrom the marked-content tag before BDC
Check
Q4. Every page has a running page number. How should a tagged PDF mark it?
As a /P structure elementWith /ActualTextAs an /Artifact in the content streamLeave it unmarked
Check
Q5. Which kind of metadata was added in PDF 1.4 and is required by PDF/A?
The document information dictionary (/Info)An XMP metadata stream (/Metadata)The /MarkInfo dictionaryThe trailer's /ID
Check
Reset5 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.