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 the level A PDF/A subsets (PDF/A-1a, PDF/A-2a, PDF/A-3a).
ExpertPdf Anywhere produces both parts of the accessibility standard: PDF/UA-1 (ISO 14289-1, on PDF 1.7) and PDF/UA-2 (ISO 14289-2, written as a PDF 2.0 document). The standard is chosen with PdfUAStandard: Pdf_UA_1 or Pdf_UA_2.
Set AccessibilityStandard to the PDF/UA part the document must declare; this turns tagging on. The structure comes from the HTML itself: write semantic HTML (h1-h6, p, ul/ol, table with th, img with alt, a with text) and the PDF gets the matching structure. Both standards require a document title and a language: Language sets the language of the document (en-US when not set), and the title is Title, or the title of the HTML page when that is not set.
PdfConverter converter = new PdfConverter(); converter.AccessibilityStandard = PdfUAStandard.Pdf_UA_1; converter.Language = "en-US"; converter.PdfDocumentInfo.Title = "Accessible report"; converter.SavePdfFromUrlToFile("https://www.example.com/report", "accessible-report.pdf");
Tagged set to true produces the same structure without choosing the part: the document then declares PDF/UA-1, or PDF/UA-2 at a PDF/A-4 level. The level A PDF/A subsets turn tagging on by themselves. Headers and footers are tagged as artifacts (decorative content that is not read).
An accessible document can also be archived: combine the PDF/UA part with a PDF/A level set in PdfStandardSubset. PDF/UA-1 combines with PDF/A-1a, PDF/A-2 and PDF/A-3; PDF/UA-2 combines with PDF/A-4. See PDF Standards.
PdfConverter converter = new PdfConverter(); // accessible and archived: PDF/A-3a with PDF/UA-1 converter.PdfStandardSubset = PdfStandardSubset.Pdf_A_3a; converter.AccessibilityStandard = PdfUAStandard.Pdf_UA_1; converter.Language = "en-US"; converter.PdfDocumentInfo.Title = "Accessible report"; converter.SavePdfFromUrlToFile("https://www.example.com/report", "accessible-report-pdfa.pdf");
When you build or extend a Document yourself, set Tagged - or declare the standard with AccessibilityStandard, which turns tagging on - before you add any content, set Language and a title, 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 tag themselves. A document that declares a standard is checked when it is saved: content that is neither tagged nor marked as an artifact makes the save fail rather than produce a document that claims a standard it does not meet. Embed the fonts (the second argument of AddFont), as PDF/UA requires.
Document document = new Document(); document.AccessibilityStandard = PdfUAStandard.Pdf_UA_1; document.Language = "en-US"; document.DocumentInformation.Title = "Tagged document"; document.ViewerPreferences.DisplayDocTitle = true; PdfPage page = document.AddPage(); PdfFont titleFont = document.AddFont( new Font("Arial", 20, FontStyle.Bold), true); PdfFont textFont = document.AddFont(new 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();