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
TitleandLanguageonTaggedContentfor PDF/UA compliance. - Build the structure tree top-down: create elements, then append children.
- Use
SetAlternativeTexton figure elements for screen-reader accessibility. - Tag tables with
THead,TBody,TFootfor proper table semantics. - Validate PDF/UA compliance with
PdfFormatConversionOptions(see Conversion guide).
Common Issues
| Issue | Cause | Fix |
|---|---|---|
| PDF/UA validation fails | Structure tree missing required elements | Ensure all content has corresponding structure elements |
| Heading order is wrong | H2 appears before H1 | Follow sequential heading hierarchy |
| Figure has no alt text | SetAlternativeText not called | Always provide alt text for illustrations |
| Table not recognized by screen reader | Missing THead/TBody structure | Use 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 / Method | Description |
|---|---|
TaggedContent | Entry point for logical structure operations |
TaggedContent.SetTitle | Set the document title for accessibility |
TaggedContent.SetLanguage | Set the document language |
ITaggedContent | Interface with factory methods for all element types |
StructureElement | Base class for all structure elements |
StructureElement.AppendChild | Add a child element to the tree |
StructureElement.SetText | Set the text content of an element |
TableElement | Accessible table structure element |
TableElement.CreateTHead | Create the table header section |
TableElement.CreateTBody | Create the table body section |
TableTRElement | Table row element |
TableTRElement.CreateTD | Add a data cell |
TableTRElement.CreateTH | Add a header cell |
IllustrationElement | Figure/illustration structure element |
IllustrationElement.SetImage | Attach an image to the illustration |