Lbl + LBody auto-generated) * figure → Figure * img[alt] → Figure + /Alt (alt text written to struct-elem dictionary) * figcaption → Caption * table → Table (tr → TR, th → TH, td → TD, caption → Caption) * a → Link */ // NOTE: local file reads (images, fonts, attachments) are restricted to an allowlist of // trusted paths that covers this package tree, so run the examples in place. To read assets // from other locations, list them in the 'allowedPaths' entry of the fileOptions constructor // parameter (see E047_remote_resources_security.php). require __DIR__ . '/../vendor/autoload.php'; \define('K_PATH_FONTS', \realpath(__DIR__ . '/../vendor/tecnickcom/tc-lib-pdf-font/target/fonts')); $pdf = new \Com\Tecnick\Pdf\Tcpdf( unit: \Com\Tecnick\Pdf\Page\Unit::Millimeter, isunicode: true, subsetfont: false, compress: true, mode: \Com\Tecnick\Pdf\PdfConformance::Pdfua1, ); $pdf->setCreator('tc-lib-pdf'); $pdf->setAuthor('Nicola Asuni'); $pdf->setTitle('PDF/UA-1 Auto-Tagged HTML'); $pdf->setSubject('tc-lib-pdf example: 016 — pdfua1 mode HTML tagging showcase'); $pdf->setKeywords('TCPDF tc-lib-pdf pdfua1 PDF/UA-1 ISO14289 tagged PDF accessibility HTML auto-tag'); $pdf->setPDFFilename('E016_pdfua1.pdf'); $pdf->setLanguage(code: 'en-US'); $font = $pdf->font->insert($pdf->pon, 'dejavusans', '', 10); // PDF/UA requires every font to be embedded. /
 default to the
// non-embedded standard-14 Courier, so register an embedded monospace font and
// select it for those elements.
$pdf->font->insert($pdf->pon, 'dejavusansmono', '', 10);
$pdf->setHTMLMonospaceFont('dejavusansmono');

$pdf->addPage();
$pdf->page->addContent($font['out']);

$imgPath = __DIR__ . '/images/tcpdf_logo.jpg';

$html =
    '

PDF/UA-1 — Auto-Tagged HTML Showcase

' . '

Mode: pdfua1 (ISO 14289-1, PDF 1.7). This document' . ' demonstrates every HTML element that addHTMLCell() auto-tags with a' . ' PDF/UA-1 structure role. PDF/UA-1 is the original accessible-PDF standard: it mandates' . ' a tagged structure tree, document language, MarkInfo /Marked true,' . ' and ViewerPreferences /DisplayDocTitle true. All of these are written' . ' automatically when the pdfua1 mode is active.

' . '

1 — Heading and Paragraph Roles

' . '

H3 Sub-heading

' . '

The h1-h6 tags map to PDF roles H1-H6.' . ' The p tag maps to P.' . ' PDF/UA-1 requires that heading levels are not skipped: the library clamps each' . ' heading to at most one level deeper than the previous heading to maintain a' . ' well-formed outline that screen readers can navigate.

' . '

2 — Block Roles

' . '
“Tagged PDF is the foundation of accessible PDF. Without a' . ' well-formed structure tree, automated tools and assistive technologies cannot' . ' reliably interpret document content.” — ISO 14289-1 rationale
' . '

The blockquote tag maps to BlockQuote.

' . '

3 — List Structure (L > LI > Lbl + LBody)

' . '

Both ul and ol map to the L role.' . ' Each li auto-generates LI > {Lbl, LBody} children:

' . '' . '
    ' . '
  1. Ordered item — the number is auto-generated as the Lbl
  2. ' . '
  3. Body text is again auto-wrapped in LBody
  4. ' . '
  5. Nesting: L > LI > {Lbl, LBody}
  6. ' . '
' . '

4 — Figure, Image Alt-Text, and Caption

' . '
' . 'TCPDF logo: blue text on white background' . '
Figure 1 — TCPDF logo. The alt attribute becomes' . ' /Alt in the Figure structure-element dictionary.' . ' PDF/UA-1 requires every Figure to carry an /Alt or /ActualText entry so' . ' screen readers can describe non-text content. The figcaption tag' . ' maps to Caption.
' . '
' . '

5 — Table Structure (Table > TR > TH/TD)

' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '
Table 1 — HTML tags and their PDF/UA-1 structure roles
HTML tagPDF structure roleCategory
h1–h6H1–H6Heading
pPBody
blockquoteBlockQuoteBody
preCodeBody
ul, olLList
liLI + Lbl + LBodyList
figureFigureIllustration
img (with alt)Figure + /AltIllustration
figcaption, captionCaptionIllustration
tableTableTable
trTRTable
tdTDTable
thTHTable
aLinkInline
' . '

6 — Hyperlink (Link Role)

' . '

This sentence contains a' . ' hyperlink to the tc-lib-pdf repository;' . ' the a element is tagged with the Link structure role' . ' automatically. PDF/UA-1 requires that link annotations have an accessible name,' . ' which the library derives from the link text in the structure tree.

' . '

7 — Rules, Spans and Empty Cells

' . '

A horizontal rule carries no semantics, so it is emitted as an Artifact' . ' rather than left as untagged content (PDF/UA-1 7.1):

' . '
' . '

Cell colspan/rowspan are recorded on the cell structure' . ' element as integer /ColSpan and /RowSpan attributes,' . ' and an empty cell is kept in the tree so the row keeps its full column count (7.2):

' . '' . '' . '' . '' . '' . '
Col ACol BCol C
Spans columns A and BC
Spans rowsB2C2
B3
'; // A long table that breaks across pages: the repeated header on each continuation // page is an Artifact, while the single Table structure element keeps all its rows. $html .= '

8 — Page-Spanning Table

' . '' . ''; for ($row = 1; $row <= 60; ++$row) { $html .= ''; } $html .= '
#Description
' . $row . 'Continuation row ' . $row . '
'; $pdf->addHTMLCell(html: $html, posx: 15, posy: 20, width: 180); $rawpdf = $pdf->getOutPDFString(); $pdf->renderPDF(rawpdf: $rawpdf);