Repository navigation
Description
HeadingRenderer maps a heading level to a structure type through a switch whose default arm is
H6. Levels past the fifth clamp to it silently, and so does every negative level.
// src/VellumPdf.Layout/Rendering/HeadingRenderer.cs:36
private static string HeadingStructType(int level) => level switch
{
0 => "H1", 1 => "H2", 2 => "H3", 3 => "H4", 4 => "H5",
_ => "H6",
};Heading.Level is public int Level { get; init; } with no validation anywhere.
Measured
Reported by VellumPdfShowcase against the published 2.3.2 package, on net10.0 Windows x64 Release,
reading the emitted structure type:
Level |
structure type |
|---|---|
| 0 | /H1 |
| 1 | /H2 |
| 5 | /H6 |
| 6 | /H6 |
| 7 | /H6 |
| 100 | /H6 |
int.MaxValue |
/H6 |
| -5 | /H6 |
Level is 0-based, so the first two rows are the intended mapping rather than an off-by-one. The
last row is the one their report does not name: the default arm catches negatives as well as
overflow, so a heading the caller numbered -5 is tagged as a sixth-level heading.
What the standard permits
ISO 14289-1:2014, 7.4.3:
If a PDF that contains the tags H1, H2, H3, H4, H5, and H6 (in any permissible sequence) requires
more headings, tags numbered from H7 upward (without limit) may be defined and used.
The same clause requires the tag be the letter H followed by Arabic numerals with no intervening
whitespace and no numerical separator, and forbids any other numbering system. So there is no
ceiling to respect, and a negative level has no valid tag at all.
Clause 7.4.2 constrains the sequence rather than the ceiling: if any heading tag is used, H1 shall
be first, and a descending sequence shall not skip a level. That is a document-level property this
library cannot enforce from a single heading, so it belongs in the member's documentation as a
caller obligation.
Why it matters beyond a wrong tag
A consumer is paying for it now. VellumPdfShowcase keeps a MaxHeadingLevel of 5 for this
reason alone, so that the level it displays and the structure the file carries agree. The cap exists
because the library clamps, not because the format has a limit.
Assistive technology reads the structure type. A document whose seventh-level headings all arrive as
H6 has lost its outline depth with no error and no diagnostic.
Scope
- Emit
H{level + 1}for any level at or above 0. - Refuse a negative level, through
LayoutValidationso the message matches the family Layout: three refusals misdescribe their input, and every pie chart refusal names a private field #481 built. - Document the 7.4.2 sequence obligation on
Heading.Level, per the rule inCONTRIBUTING.md, since
the library cannot check it. - A test per row of the table above, asserting the emitted structure type rather than that bytes came
back.
Considered and rejected
Refusing a level above 5 instead of honouring it. It leaves the showcase needing its cap, which is
the cost this issue exists to remove, and 7.4.3 is explicit that H7 upward is permitted.
Found while planning 2.3.3, from the showcase's re-measurement of the published package. The
negative-level row and the clause reading are mine.
Activity
Tim81 commentedon Nov 18, 2026
The 2026-11-16 handbook research confirms the issue and adds a decision for v2.4. One correction to how it was
summarised elsewhere.
Levels are zero-based.
HeadingRenderer.cs:36-44:So level 5 maps to H6, which is correct. The clamp begins at level 6, which should be H7; level 6 and every higher
level, and every negative level, map to H6. The research's observation (
Level = 6gaveH6directly afterH1)is consistent with this table, and the table in this issue already has the same rows. I could not find an
off-by-one in either; where a summary says "level 5" or "level 6" is the first wrong one, the code says level 6.
ISO 14289-1 7.4.3 allows H7 and higher (
Hfollowed by Arabic numerals), so the fix isH{level + 1}for anylevel at or above 0, as this issue proposes.
Change for v2.4 against the scope above: a negative level, and a skipped level (7.4.2: if any heading tag is
used, H1 is first and a descending sequence does not skip a level; the research's
ua-headingskipfile, H1 thenH3, failed veraPDF 7.4.2-1 and saved without a report), are reported through the diagnostics channel (#607).
Strict mode (opt-in) refuses them. Refusal by default is 3.0 (#484), so the "refuse a negative level through
LayoutValidation" line moves to strict mode. The H7+ mapping itself changes bytes only for levels that arewrong today.
test: pin structure and artifact output to its ISO clauses (#761)
Tim81 commentedon Nov 29, 2026
The ISO audit (
docs/conformance-v2.4.md) has skipped tests that wait on this issue; the fix removes their skip and makes them pass.Iso14289_1_7_4_3_AHeadingPastTheSixthLevelIsAnH7(group G3)