Heading levels follow font size and skip levels; tagged output fails PDF/UA-1 7.4.2-1

Author: wittjeffCreated Sep 23, 2026Updated Sep 23, 2026

What happens. In the JSON and in the tagged-PDF output, heading level is assigned from the heading's font size. A document whose section titles are set in three or four sizes therefore opens at H4 or steps H1 → H4 → H6. On GovDocs1 000145.pdf (a 2-page US government notice) the heading sequence in the JSON is 1, 4, 6, 2, 5, 3; on 000029.pdf it is 4, 6, 3, 4, 4, 6, 6, 3, …; on 000018.pdf it is 5, 4.

veraPDF on --format tagged-pdf output for 000145.pdf:

7.4.2-1  For documents that are not strongly structured … a descending sequence of
         headers shall proceed in strict numerical order and shall not skip an
         intervening heading level.   context: …/SEDocument Document)/K[10](SEHn H4)

Across the first 135 short PDFs of GovDocs1 archive 000, 8 documents fail this rule through ODL's heading levels (0 through docling's, which derive levels from a hierarchy model). The same 8 documents pass once the levels are renumbered.

Why it matters. PDF/UA-1 (ISO 14289-1) 7.4.2 and the Matterhorn Protocol checkpoint 14-003 require that a descent never skips a level; UA-2 keeps the rule. A tagged output that fails it is not conformant however good the rest of the tree is. Font size is a fine signal for which text is a heading and for relative depth; it is not an outline level.

Suggested fix (rule-based, no model). Renumber levels in document order so every descent is one level at a time, going back up may jump, and the first heading is H1. Keep a path of (source level, output level) pairs:

path = []                       # (source level, output level)
for heading in document_order:
    while path and path[-1].source > heading.source:
        path.pop()              # closing deeper sections
    if path and path[-1].source == heading.source:
        out = path[-1].output   # a sibling at a known depth
    else:
        out = (path[-1].output + 1) if path else 1
        path.append((heading.source, out))
    heading.level = min(out, 6)

1, 4, 6, 2, 5, 3 becomes 1, 2, 3, 2, 3, 3; 5, 4 becomes 1, 1. A document title that is not a heading (PDF 2.0 Title) tops the outline, so an H2 may follow it. This is deterministic, cheap, and leaves the font-size levels available as the relative signal they are (they could stay in the JSON as a separate field).

I have this running as a post-processing step on our side and can send a PR against the Java code if that is welcome; the algorithm above is the whole of it.

Source: opendataloader-project/opendataloader-pdf