Skip to content

Fix PDF/UA-1 conformance defects found auditing #325 - #389

Merged
jakejackson1 merged 11 commits into
feature/pdfua-1-supportfrom
fix/pdfua-conformance
Sep 23, 2026
Merged

jakejackson1 merged 11 commits into
feature/pdfua-1-supportfrom
fix/pdfua-conformance

Conversation

@jakejackson1

Copy link
Copy Markdown
Member

Fixes for defects found while auditing #325's PDF/UA-1 output. I generated about 70 HTML documents and 14 direct-API documents with PDFUA on (headings, lists, tables across pages, images, SVG, links, forms, TOC, languages, RTL, CJK and Indic, watermarks, backgrounds, PDF/A), and re-imported each one with mPDF's own importer. Every document went through veraPDF 1.30 --flavour ua1, and the ones veraPDF can't judge were checked by hand.

Defects fixed

Each defect is its own commit, with tests.

  1. /Headers written as names. ISO 32000-1 Table 344 makes it an array of byte strings matching the TH /ID, but it was written as [/col1]. veraPDF doesn't check this (bogus IDs pass too). To reproduce: <table><tr><th id="a">A</th></tr><tr><td headers="a">1</td></tr></table>.
  2. Mixed content out of reading order (Matterhorn 09-001). An element's /K listed its children before its own MCIDs, so <p>Claim<sup><a href="#fn">1</a></sup>.</p> read as "1 Claim ." and <p>Hello <span lang="de">Guten Tag</span></p> read as "Guten Tag Hello". Kids are now merged by drawing order.
  3. Form fields at the end of the document (09-001). Every Form element was appended to the Document when the widgets were written, far from its label. It is now created where the widget is drawn.
  4. Repeated table header and footer rows tagged as content. A 120-row table with <thead> gave its TH one MCID per page, so the header was read on every page. Repeats are now artifacts. A <tfoot> written before <tbody> was also read before the body; it is now written after the last TBody.
  5. <figure> without /Alt (veraPDF 7.3-1). <figure><img alt="x"><figcaption>…</figcaption></figure> and <div role="figure"> gave a Figure with no /Alt. An unnamed figure is now a Div. An unnamed role="img" block throws, or becomes a Div under PDFUAauto.
  6. Decorative and inline-SVG images.
    • <img role="presentation"> (or role="none" or aria-hidden="true") without alt threw in strict mode.
    • <svg aria-label="…"> lost its attributes when turned into an <img> and threw for a missing alt.
  7. PDF/A + PDF/UA failed PDF/A. pdfuaid:part was not declared in a pdfaExtension schema (ISO 19005-1 §6.7.8, 19005-2 §6.6.2.3.2; veraPDF 1b 6.7.9-2/-3, 2b 6.6.2.3.1-1/-2). PDFA + PDFAversion => '2-B' + PDFUA now passes both ua1 and 2b.
  8. Importing tagged mPDF output. Only /Alt, /ActualText and /Lang were copied.
    • Imported tables failed 7.5-1 (TH without /Scope) and 7.2-42 (lost /ColSpan).
    • An imported form field left an empty Form element (7.18.4-2).
    • A link around an image threw in strict mode.
    • /Scope, /ColSpan, /RowSpan, /ListNumbering and /Placement are now copied, and Form and Link elements left empty are dropped.
  9. Imported links wrote /Contents and /F twice in one annotation dictionary. The source's /Contents is kept, and the host's /F is written.

A final commit pulls out StructType::isPresentational() and StructureTree::addLeaf() so BlockTag, Img, Form and the annotation writer share them.

Found but not fixed (for discussion)

  • The direct drawing API is untagged. Cell(), MultiCell(), Write(), Text(), WriteText(), WriteCell(), CircularText(), Shaded_box(), Rect() and Line() fail veraPDF 7.1-3 ($mpdf->WriteHTML('<h1>x</h1>'); $mpdf->Cell(40, 10, 'Text');). AutosizeText(), Image() and WriteFixedPosHTML() are fine. To fix this, someone has to decide what each call is tagged as (a P per call? graphics as artifacts?).
  • No title under PDFUAauto. It only warns, and the output fails 7.1-9. It could fall back to the first heading or an HTML <title>.
  • Inactive form fields are artifacts. With useActiveForms off, a text input's printed value and a checkbox's state are artifacts, so the information is hidden from assistive technology.
  • RTL runs are drawn in visual order with no /ActualText or /ReversedChars. pdftotext reads مرحبا بالعالم back with its words reversed.
  • Nested marked content. An inline image's Figure MCID sits inside the paragraph's MCID. No validator flags it.
  • <a href><img alt="…"></a> puts the Figure beside the Link, not inside it, so the Link's only content is its annotation.
  • Within one line, an object comes after the text of that line. mPDF draws objects at the end of the line, so the Form or Figure falls after the line's text: [ ] Check reads "Check, checkbox".
  • Imported links get their own Link element at the end of the Document and aren't matched to the Link cloned from the source.
  • Tag documents for PDF/UA-1 when the PDFUA option is set #325 now conflicts with gravitypdf in 7 files: Form, FpdiTrait, Mpdf, Protection, BaseWriter, FontWriter and MetadataWriter. gravitypdf has since fixed the ToUnicode CMap for every document (The ToUnicode CMap of every CID font maps the whole two-byte space in a single bfrange, which may not cross a high-byte boundary #344/Write the ToUnicode CMap of a CID font in ranges that stay inside one high byte #362), which makes the PR's PDF/UA-only identityRanges() redundant, and it moved encryption to AES-256.
  • PDF/A-1b + PDF/UA still fails 1b 6.3.5-3 (no CIDSet), as PDF/A-1b does without PDF/UA. That's left to Write PDF/A-2b and PDF/A-2u documents that keep their transparency #330.

Verification

Before After
HTML documents failing ua1 4 (figure, role=figure, no title under auto, direct API) 1 (no title under auto) + the direct-API one
Direct drawing API documents failing ua1 11 of 14 11 of 14 (not fixed)
Re-imported tagged documents failing ua1 (excluding direct API) 10, plus one exception 0
PDF/A-2b + UA fails 2b passes ua1 and 2b
  • composer test (PHP 8.5, CI=1, Imagick + Ghostscript): 3732 tests OK, 71 skipped (the veraPDF group without VERAPDF_BIN, plus the usual generator skips).
  • VERAPDF_BIN=… phpunit --group=verapdf: 66 of 66 pass. Three are new: figure with caption, PDF/A-2b + UA, and tagged import of a table, form and link.
  • composer test -- --group=snapshot: 86 of 86 pass. The pdfua fixture is refreshed: two paragraphs now list their own text before their Link or Figure, and the XMP document id changes with the output. The pages are identical.
  • composer cs clean. PHPStan 2 level 2 clean. Changed files lint under PHP 5.6.

🤖 Generated with Claude Code

jakejackson1 and others added 11 commits September 23, 2026 13:35
…' /ID

ISO 32000-1 Table 344 makes /Headers an array of byte strings, each the
/ID of a TH. They were written as names, which a reader matching them to
the TH's /ID string does not find. veraPDF does not look at /Headers, so
this showed only by hand.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An element's /K listed its children first and its own marked content
after them. A link or a span with a lang is opened when its tag is read,
before the text of its paragraph is drawn, so "Claim<a>1</a>." was read
as "1 Claim ." (Matterhorn 09-001). Marked content is numbered as it is
drawn, so the writer now puts each child after the parent's content
drawn before it, and a child with no content after the content its
parent had when it was added.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Every Form element was made when the widgets were written and added to
the end of the Document, so a screen reader met all the fields after the
last paragraph, far from their labels (Matterhorn 09-001). The element
is now made when the widget is drawn, inside the element around it, and
the widget joins it when written.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…body

The rows a table repeats at each page break were tagged as more content
of the same TH and TD, so a screen reader read the header once per page.
They are now artifacts. A <tfoot> written before <tbody>, as HTML 4
asked, was also read before the body; the TFoot is now written after the
last TBody.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ption

<figure> and role="figure" were tagged Figure however they were named,
so a figure holding an <img alt> and a <figcaption> left a Figure with
no /Alt around another Figure, which veraPDF rejects (ISO 14289-1 §7.3,
Matterhorn 13-004). Without aria-label or aria-labelledby the figure is
now a Div. A block with role="img" and no name throws, as an <img>
without alt does, and is a Div under PDFUAauto.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
An <img> without alt that role="presentation", role="none" or
aria-hidden="true" marks as decorative threw in strict mode instead of
being drawn as an artifact. An inline <svg> lost its role and aria-*
attributes when it was turned into an <img>, so an <svg aria-label>
threw for a missing alt, and under PDFUAauto its name was dropped. Those
attributes now go across with its class.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
PDF/A allows only the XMP schemas it names and those declared in a
pdfaExtension schema (ISO 19005-1 §6.7.8, ISO 19005-2 §6.6.2.3.2), so a
document with PDFA and PDFUA both on failed PDF/A over its
pdfuaid:part. The schema is now declared when both are on; a PDF/A-2b
document now passes both ua1 and 2b.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ts widgets leave empty

Importing a tagged page copied only /Alt, /ActualText and /Lang, so its
header cells lost /Scope and its cells their spans; importing mPDF's own
PDF/UA output with a table failed veraPDF (7.5-1, 7.2-42). /Scope,
/ColSpan, /RowSpan, /ListNumbering and /Placement now come across.

A widget is not imported, and an imported link is given an element of
its own, so the copied Form or Link element was left with nothing:
veraPDF rejected the Form (7.18.4-2) and strict mode threw for the Link.
Such an element is now dropped.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
FPDI hands over an imported link's own entries, which the writer added
after its own /Contents and /F, so under PDF/UA both keys appeared twice
in the one annotation dictionary. The source's /Contents is now kept in
place of the generated one, and its /F gives way to the flags PDF/A and
PDF/UA need.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… link

Two paragraphs list their own text before the Link and Figure inside
them; the XMP document id, a hash of the output, changes with them. The
pages are the same.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
BlockTag and Img each tested role="none"/"presentation" and aria-hidden,
and already differed over trimming; StructType::isPresentational() now
answers for both. Form and the annotation writer made an empty Form or
Link by opening, reading and closing; StructureTree::addLeaf() does it.
The importer reads /A with normaliseKidsToArray() in one loop, the
writer skips the reading-order merge where there is nothing to merge,
and an inline SVG's ARIA attributes are read only under PDF/UA.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant