Logical Structure

Logical Structure

Tagged PDFs include a logical structure tree that defines the document’s semantic hierarchy — paragraphs, headings, tables, figures, and lists. Aspose.PDF FOSS for .NET provides the TaggedContent API for building and inspecting this structure, which is essential for PDF/UA accessibility compliance.


Accessing tagged content

using var doc = new Document();
var tagged = doc.TaggedContent;
tagged.SetTitle("Accessible Document");
tagged.SetLanguage("en-US");

Creating structure elements

ITaggedContent provides factory methods for every standard structure element type. Elements are assembled into a tree by calling AppendChild.

var root = tagged.RootElement;

var heading = tagged.CreateHeaderElement(1);
heading.SetText("Chapter 1");
root.AppendChild(heading);

var paragraph = tagged.CreateParagraphElement();
paragraph.SetText("This is the first paragraph.");
root.AppendChild(paragraph);

Structured tables

TableElement creates accessible tables with head, body, and footer sections.

var table = tagged.CreateTableElement();
root.AppendChild(table);

var thead = table.CreateTHead();
var headerRow = thead.CreateTR();
headerRow.CreateTH().SetText("Name");
headerRow.CreateTH().SetText("Value");

var tbody = table.CreateTBody();
var dataRow = tbody.CreateTR();
dataRow.CreateTD().SetText("Width");
dataRow.CreateTD().SetText("612");

Illustrations and figures

IllustrationElement wraps images in the structure tree.

var figure = tagged.CreateFigureElement();
figure.SetImage("chart.png");
figure.SetAlternativeText("Sales chart for Q4");
root.AppendChild(figure);

Structure element types

The API supports the full set of PDF structure element types:

  • Block-level: Paragraph, Heading (H1-H6), List, ListItem, Table, BlockQuote, Code
  • Inline: Span, Link, Annotation, Figure, Formula
  • Grouping: Division, Article, Section, Part

Tips and Best Practices

  • Always set Title and Language on TaggedContent for PDF/UA compliance.
  • Build the structure tree top-down: create elements, then append children.
  • Use SetAlternativeText on figure elements for screen-reader accessibility.
  • Tag tables with THead, TBody, TFoot for proper table semantics.
  • Validate PDF/UA compliance with PdfFormatConversionOptions (see Conversion guide).

Common Issues

IssueCauseFix
PDF/UA validation failsStructure tree missing required elementsEnsure all content has corresponding structure elements
Heading order is wrongH2 appears before H1Follow sequential heading hierarchy
Figure has no alt textSetAlternativeText not calledAlways provide alt text for illustrations
Table not recognized by screen readerMissing THead/TBody structureUse the full table structure API

FAQ

What is a tagged PDF?

A tagged PDF includes a logical structure tree that maps visual content to semantic elements (headings, paragraphs, tables), enabling accessibility tools and content reflow.

Is tagged PDF the same as PDF/UA?

PDF/UA is a standard that requires tagging plus additional accessibility rules. Tagged PDFs are a prerequisite for PDF/UA compliance.

Can I tag an existing PDF?

The TaggedContent API works best with documents created from scratch. For existing PDFs, inspect the structure tree through Document.TaggedContent.


API Reference Summary

Class / MethodDescription
TaggedContentEntry point for logical structure operations
TaggedContent.SetTitleSet the document title for accessibility
TaggedContent.SetLanguageSet the document language
ITaggedContentInterface with factory methods for all element types
StructureElementBase class for all structure elements
StructureElement.AppendChildAdd a child element to the tree
StructureElement.SetTextSet the text content of an element
TableElementAccessible table structure element
TableElement.CreateTHeadCreate the table header section
TableElement.CreateTBodyCreate the table body section
TableTRElementTable row element
TableTRElement.CreateTDAdd a data cell
TableTRElement.CreateTHAdd a header cell
IllustrationElementFigure/illustration structure element
IllustrationElement.SetImageAttach an image to the illustration

See Also

 English