Tagged PDF and Accessibility (PDF/UA) |
A tagged PDF carries the logical structure of the document - headings, paragraphs, lists, tables, figures with their alternate text, links, and the reading order - next to its visual content. Screen readers and other assistive technology use it, and it is required for accessible documents (PDF/UA, ISO 14289) and for PDF/A-3a.
HTML added with an HtmlToPdfElement rendered with the Chromium or Blink engine is tagged from the HTML itself: write semantic HTML (h1-h6, p, lists, tables with th, images with alt) and the element adds the matching structure to a tagged document. The WebKit engines cannot tag their output.
Set Tagged and say how every element you add is tagged:
TagType - the structure type of real content (PdfTagType: Paragraph, Heading1, Figure, Table...).
AlternateText - the description of a figure, read instead of it.
ActualText - the text of content drawn as graphics.
Artifact - decorative content (rules, backgrounds, page numbers), left out of the structure.
BeginTag(PdfTagType) and EndTag - group elements in containers (Section, List, Table...).
An element added to a tagged document without a TagType and not marked as an Artifact is refused, so nothing ends up outside the structure by mistake. Link elements and HTML elements rendered with Chromium or Blink tag themselves.
Document document = new Document(); document.Tagged = true; document.Language = "en-US"; document.DocumentInformation.Title = "Tagged document"; PdfPage page = document.AddPage(); PdfFont titleFont = document.AddFont(new System.Drawing.Font("Arial", 20, System.Drawing.FontStyle.Bold), true); PdfFont textFont = document.AddFont(new System.Drawing.Font("Arial", 11), true); document.BeginTag(PdfTagType.Section); TextElement title = new TextElement(0, 0, "Quarterly results", titleFont); title.TagType = PdfTagType.Heading1; page.AddElement(title); TextElement paragraph = new TextElement(0, 40, "Sales grew in every region.", textFont); paragraph.TagType = PdfTagType.Paragraph; page.AddElement(paragraph); // a decorative rule: not part of the structure RectangleElement rule = new RectangleElement(0, 30, 300, 1); rule.Artifact = true; page.AddElement(rule); document.EndTag(); document.Save("tagged.pdf"); document.Close();