
A tagged PDF uses XML‑like tags to describe the logical structure of its content, making the document fully accessible to screen readers and other assistive technologies. In this step‑by‑step tutorial we’ll use Aspose.PDF for Java to create tagged PDFs, add nested elements, apply custom text styling, and illustrate structure elements—all programmatically. If you’re familiar with basic PDF generation in Java, you’re ready to enhance your PDFs for accessibility.
- Java API to Create Tagged PDF Files
- Create a Tagged PDF File
- Create a Tagged PDF with Nested Elements
- Styling Text Structure in a Tagged PDF
- Illustrating Structure Elements in a Tagged PDF
Java API to Create Tagged PDF Files
To generate tagged PDFs, we rely on Aspose.PDF for Java, a leading Java library for PDF creation and manipulation. The API supports seamless creation, processing, and conversion of both simple and complex PDF layouts. Download the library or add it to your Maven project with the snippets below.
Repository:
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
Dependency:
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>22.4</version>
</dependency>
Create a Tagged PDF File in Java
Aspose.PDF for Java provides the ITaggedContent interface to work with PDF tags. Follow these steps to build a basic tagged PDF:
- Create a new PDF using the Document class.
- Retrieve the TaggedContent object from the document and store it in an ITaggedContent variable.
- Set the document title, header, and language, then add elements through the ITaggedContent instance.
- Generate a ParagraphElement with ITaggedContent.createParagraphElement() and assign its text.
- Append the paragraph to the root element via ITaggedContent.getRootElement().appendChild().
- Save the PDF using Document.save(String).
The code sample below demonstrates how to create a tagged PDF in Java.
The resulting PDF looks like this:

Create a Tagged PDF with Nested Elements in Java
Building on the previous example, you can embed nested elements such as spans inside paragraphs. Follow these steps:
- Open a new or existing PDF with the Document class.
- Access the TaggedContent and assign it to an ITaggedContent variable.
- Define title, header, and language, then add elements via the ITaggedContent object.
- Create a ParagraphElement using ITaggedContent.createParagraphElement() and set its text.
- Use the SpanElement class to insert nested content.
- Attach the span to the paragraph with ParagraphElement.appendChild().
- Append the paragraph to the root element via ITaggedContent.getRootElement().appendChild().
- Save the final document with Document.save(String).
The snippet below adds nested elements to a tagged PDF.
The generated PDF displays nested elements as shown below.

Styling Text Structure in a Tagged PDF
Aspose.PDF for Java lets you customize text appearance within tagged PDFs. Use the StructureTextState class to set font family, size, style, and color. The example below applies custom styling to a tagged paragraph.
Illustrating Structure Elements in a Tagged PDF in Java
To visually represent structure elements, the library provides the IllustrationElement class. The following code demonstrates how to add illustration elements to a tagged PDF.
Get a Free License
You can get a free temporary license to use Aspose.PDF for Java without evaluation restrictions.
Conclusion
This guide showed how to create accessible, tagged PDF files in Java, add nested elements, apply text styling, and illustrate structure elements using Aspose.PDF. Explore the full Java PDF API in the documentation and reach out via our forum for any questions.