Technical Article

PDF/UA-2 needs its own checker in PDF Library for Delphi

A PDF 2.0 invoice tagged for PDF/UA-2 can carry footnotes as FENote elements in the http://iso.org/pdf2/ssn namespace, with a custom /InvoiceLine role mapped to TR through that namespace's /RoleMapNS dictionary. Hand the same file to rules written for PDF/UA-1 and it receives a verdict that is wrong in both directions. Those rules read only the flat /RoleMap in the structure tree root, so InvoiceLine looks unmapped and FENote looks like an unknown custom type. And if one chapter still uses an unnumbered H heading, which PDF/UA-1 tolerates and PDF/UA-2 prohibits, nothing flags it

Three findings, and every one of them concerns the checker rather than the file. PDF/UA-2 (ISO 14289-2) needs a rule set of its own, one that reads namespaces the way ISO 32000-2 defines them and knows which PDF/UA-1 habits no longer apply

Why PDF/UA-1 rules misread a PDF/UA-2 file

PDF/UA-1 sits on PDF 1.7 and a single role map. PDF/UA-2 sits on PDF 2.0, where any structure element can carry an /NS entry pointing at a namespace dictionary, and each namespace brings its own /RoleMapNS. Headings are H1 through Hn with no six-level ceiling, notes are FENote, and the unnumbered H has gone. A rule such as "every Note needs an ID" made sense in 2012; transplanted onto a PDF 2.0 tree, it grumbles about a vocabulary the file never used

In PDF Library for Delphi (PDFlibPas), CheckFilePDFUACompliance with a target part of 2 runs a dedicated PDF/UA-2 profile. The checks for identification, title metadata, /MarkInfo and DisplayDocTitle look familiar, but the structure walk is written for namespaces from the outset. Reports produced from it label every diagnostic as ISO 14289-2, including the ones that share wording with the UA-1 checker

Clause numbers get the opposite treatment. Where the mapping from a diagnostic to a specific ISO 14289-2 clause has not been confirmed against the standard text, the clause field in the XML or JSON report is left empty. We would rather have that blank than a borrowed UA-1 clause number: an auditor who sees an empty field goes off and reads the standard, whereas one who sees a confident clause number copied from PDF/UA-1 trusts it and cites the wrong section of the wrong document

How role resolution through RoleMapNS works

Assistive technology only understands standard roles, so the core of PDF/UA-2 structure validation is following each custom role, such as /InvoiceLine, until it lands on one like TR

The walk starts from an element's /S name and its /NS namespace. With no /NS, the element sits in the PDF 1.7 standard namespace and the legacy /RoleMap applies. With a namespace, that namespace's /RoleMapNS applies, and a mapping value can be either a plain name or a two-element array [/Role namespaceRef] that hops into another namespace. Each hop is recorded as a (namespace URI, role) pair, so a chain that revisits a pair is caught as a loop on the spot. The rules that follow from this:

  • A namespace referenced from a structure element must be an indirect dictionary with a non-empty /NS URI, and it must appear in the structure tree root's /Namespaces array (diagnostic 10054)
  • A custom role has to end on a standard role in the PDF 1.7 namespace, the PDF 2.0 namespace or the MathML namespace; circular chains, dead ends and role maps that are not dictionaries are reported as 10055
  • A standard role may not be remapped to a custom one, a role may not be remapped within its own explicit namespace, and the PDF 2.0 namespace may only hold its own standard types (also 10055)
  • The structure tree root needs exactly one child, a Document element that resolves into the PDF 2.0 namespace (10057), and every element's /P must point at the parent it actually hangs under (10058)
  • A role that resolves to the unnumbered H, or to Note in the PDF 1.7 namespace, is reported as 10056

One design decision is worth borrowing for your own tooling. PDFlibPas resolves every entry in every declared role map, including entries that no element in the tree currently uses. An orphaned mapping to nowhere looks harmless today, but the next template change that starts emitting that role inherits the broken chain, and by then nobody can remember where the mapping came from

MathML is treated exactly like the other namespaces. Element names in http://www.w3.org/1998/Math/MathML are checked against the MathML vocabulary, and a math element whose parent is not Formula produces 10073, following ISO 14289-2 §8.2.5.29

PDFlibPas PDF/UA-2 role resolution through RoleMapNS in Delphi: a custom /S role maps across namespaces via two-element arrays until it lands on a standard role in the PDF 1.7, PDF 2.0 or MathML namespace, with diagnostics 10054, 10055 and 10056 for broken chains
PDFlibPas walks /RoleMapNS chains across PDF 2.0 namespaces until each custom role lands on a standard role, reporting loops and dead ends as diagnostics 10054, 10055 and 10056

Running a PDF/UA-2 check from Delphi

CheckFilePDFUACompliance takes the file name, password, target part and options, and returns a string list handle with one coded finding per line. The compliance methods are implemented on TPDFlibEnterprise; the same calls on a plain TPDFlib return 0 and set an "Enterprise required" error code

uses
  System.SysUtils, PDFlibrary, PDFlibEnterprise;

procedure CheckUA2(const FileName: string);
var
  Lib: TPDFlibEnterprise;
  Issues, I, Err: Integer;
begin
  Lib := TPDFlibEnterprise.Create;
  try
    // TargetPart: 0 = follow XMP pdfuaid:part, 1 = PDF/UA-1, 2 = PDF/UA-2
    // Options: 1 = stop at the first finding, 0 = collect every finding
    Issues := Lib.CheckFilePDFUACompliance(FileName, '', 2, 0);
    Err := Lib.LastErrorCode;  // reading LastErrorCode resets it, so read it once
    if Issues = 0 then
    begin
      if Err <> 0 then
        Writeln('Check did not run, error ', Err)  // 401 = not opened or bad TargetPart, 404 = wrong password
      else
        Writeln('No findings from the implemented PDF/UA-2 checks');
      Exit;
    end;
    try
      for I := 1 to Lib.GetStringListCount(Issues) do  // items are 1-based
        Writeln(Lib.GetStringListItem(Issues, I));
    finally
      Lib.ReleaseStringList(Issues);
    end;
  finally
    Lib.Free;
  end;
end;

LastErrorCode returns the stored code and clears it in the same call, so a pattern that tests Lib.LastErrorCode <> 0 and then prints Lib.LastErrorCode on the next line will always print 0. Capture it into a local variable straight after the call you care about

Pass the target part explicitly for anything your own code generates. A target of 0 reads pdfuaid:part from the XMP metadata and switches to the UA-2 profile only when that value is 2; anything else, including a missing identification, gets the UA-1 rules. Fine for an inbox of files from unknown producers; wrong for your own output, because a generator that forgot to write the identification gets validated against the wrong standard and may come back clean. With an explicit 2, the same file reports 10050 for the missing part, 10051 if pdfuaid:rev is not 2024, 10052 if the effective PDF version is not 2.0, and 10053 if the identification properties are not bound to the pdfuaid namespace prefix

The identification is read with a namespace-aware XML parser, so pdfuaid:part written as an attribute on rdf:Description and written as a child element are both accepted; what matters is the namespace binding, not the spelling of the prefix in one tool's output. On the authoring side, SetPDFUA2Mode writes the identification, raises the document to PDF 2.0, sets /Marked and DisplayDocTitle, and makes the PDF 2.0 structure namespace the default for new elements. The namespace model behind that call is covered in the PDF 2.0, PDF/A-4, and PDF/UA-2 namespaces walkthrough

What happens when the checker cannot finish?

It tells you so. Diagnostic 10059 covers every case where the PDF/UA-2 checker stopped before reading the whole structure, and an empty result is never produced for a run that was cut short

Structure trees are untrusted input. A damaged or hostile file can nest elements thousands of levels deep, point a child back at its own ancestor, or chain a role map through hundreds of namespaces. A validator without limits hangs or overflows the stack on such a file. A validator with limits but no diagnostic is worse: it stops early, finds nothing wrong in the part it read, and returns a pass. So the limits are fixed and published in the coverage JSON:

  • Structure depth 256 and 100,000 structure objects; exceeding either produces 10059 and ends the walk
  • 256 hops along any role-map chain; a chain still going after that produces 10059
  • A structure node reached twice, through a cycle or a reused child, produces 10059 at the point of reuse
  • A structure object the parser could not fully decode within its own limits produces 10059 and stops the walk

For a file that nests 300 levels of Div, the walk stops as soon as it passes depth 256 with "structure traversal exceeds supported depth or object count", and the remaining structure, annotation and font checks for that run are skipped rather than reported as clean

PDFlibPas fail-closed PDF/UA-2 validation budgets in Delphi: structure depth 256, 100,000 structure objects and 256 RoleMapNS hops, with diagnostic 10059 emitted when the reader hits a limit, a cycle or a structure object it cannot fully decode, and a result without diagnostics never promoted to a pass
The PDF/UA-2 checker fails closed: traversal budgets of 256 levels, 100,000 structure objects and 256 role-map hops turn an unfinished read into diagnostic 10059 instead of a false pass

The same rule applies one level up. If the underlying audit returns a score below 100 with no finding lines, which happens when parsing aborts before any rule runs, the method inserts "10059 PDF/UA reader validation could not complete" so the list is never empty. An exception raised during the check becomes a 10059 line carrying the exception message. A file that cannot be opened at all never reaches the checker: the call returns 0 and LastErrorCode holds 401, or 404 for a wrong password, which is why the first example reads the error code before it trusts an empty result

One parse for PDF/A and PDF/UA-2

Batch preflight usually wants PDF/A and PDF/UA answers for the same file. The validation pipeline API opens the file once and runs several checks against that shared parse, and RunPDFUAValidationPipelineTask is its PDF/UA member, taking the same target part values as the one-call method

var
  Pipe, PDFAIssues, UAIssues: Integer;
  Json: WideString;
begin
  Pipe := Lib.BeginValidationPipeline('archive.pdf', '');
  if Pipe = 0 then
    Exit;  // Lib.LastErrorCode says why: 401 or 404
  try
    PDFAIssues := Lib.RunValidationPipelineTask(Pipe, 1, 0);     // 1 = PDF/A
    UAIssues := Lib.RunPDFUAValidationPipelineTask(Pipe, 2, 0);  // PDF/UA-2
    // ... read each nonzero handle as in CheckUA2, then ReleaseStringList ...
    Writeln('Parses: ', Lib.GetValidationPipelineParseCount(Pipe));
    // ComplianceTests: 1 = PDF/A, 2 = PDF/UA, 0 = both; ReportFormat: 0 = XML, 1 = JSON
    Json := Lib.CreateValidationPipelineReport(Pipe, 0, 0, 1);
  finally
    Lib.ReleaseValidationPipeline(Pipe);
  end;
end;

When the file identifies itself as part 2, the structured report labels its accessibility section PDF/UA-2 and ISO 14289-2, and every PDF/UA section carries "fullCertification": false alongside the embedded coverage object. The plain-text preflight report adds one line: "Coverage: implemented checks only; full accessibility certification requires additional validation and human review". Report formats, rule IDs and CI gating are covered in the PDF/A and PDF/UA preflight guide

What does the coverage report guarantee?

GetPDFUAReadValidationCoverageJSON guarantees an exact statement of what the PDF/UA-2 checker examined and what it left to people. For part 2 it returns fullCertification fixed at false, a checked array, an unverified array, and the three traversal limits

uses
  System.IOUtils, System.SysUtils;

var
  Coverage: WideString;
begin
  Coverage := Lib.GetPDFUAReadValidationCoverageJSON(2);
  // Store it next to the findings from the same run
  TFile.WriteAllText('report.coverage.json', Coverage, TEncoding.UTF8);
  if Pos('"fullCertification":false', Coverage) > 0 then
    Writeln('Machine checks only; schedule a human accessibility review');
end;

The checked array is a long one: identification (part, revision, prefix), effective PDF version, title metadata, /Marked, DisplayDocTitle, namespace references, role-map resolution, the document root, structure parents, tree cycles, the H and Note rules, fonts and Unicode mapping, annotations and forms, natural language, alternative descriptions, structure containment, content-tagging completeness, artifact nesting and the MathML vocabulary. The unverified array has three entries: logical reading order, whether content classed as real content or artifact was classed correctly, and human accessibility review

That second list is short for a reason. No parser can decide whether the reading order makes sense to someone listening to it, or whether the decorative rule on page 4 really is decorative. A checker can confirm that a Figure has a non-empty /Alt (10061); it cannot confirm that the text describes the chart

Coverage report returned by GetPDFUAReadValidationCoverageJSON(2) in PDFlibPas for Delphi PDF/UA-2 validation: fullCertification stays false while the checked array lists identification, PDF version, namespaces, role-map resolution, structure parents and cycles, fonts, annotations, alt text, content tagging and the MathML vocabulary, and the unverified array lists logical reading order, real content versus artifact classification and human accessibility review
GetPDFUAReadValidationCoverageJSON separates what the PDF/UA-2 checker examined from what it did not, so fullCertification stays false and the exact scope can be archived with every run

Our advice is blunt: archive the coverage JSON with every validation result, every time. Accessibility results end up in procurement spreadsheets, and a year later somebody asks what "passed" meant on a given date. The JSON from that run answers the question

Cross-checking against veraPDF

veraPDF with its ua2 profile is the obvious second opinion, and the cheapest way to calibrate the two tools against one another is with files you break on purpose. Take a known-good PDF/UA-2 file and make two copies: change pdfuaid:rev to 2023 in one, and retag a heading as H in the other. PDFlibPas should report 10051 for the first and 10056 for the second; check what veraPDF makes of each on your own installation

Where the two tools disagree on a real production file, read the rule text behind each finding before deciding which tool is right. A disagreement usually marks the edge of what one of them checks, which tells the accessibility reviewer where to spend the manual pass. For the authoring side, building trees that resolve cleanly in the first place, see the tagged PDF structure tree guide

The PDF/UA-2 profile, the shared-parse validation pipeline and the coverage report are part of the Enterprise edition of the losLab PDF Library for Delphi, next to PDF/A preflight and the PDF 2.0 tagging APIs that produce the files you are checking