Create Tagged PDF Files in C# .NET

A tagged PDF file is a type of PDF that uses tags to define the logical structure of the content in the document. It is used to enhance the reading experience for those who use assistive technologies and screen readers. In a previous post, we covered creating PDF files within a .NET application. In this article, we will demonstrate how to create tagged PDF files programmatically in C# .NET.

C# Library to Create Tagged PDF - Free Download

To create tagged PDF files, we will use Aspose.PDF for .NET. It is a robust library for PDF generation and manipulation in .NET applications. Using the library, you can seamlessly create, process, and convert PDF files of simple and complex layouts. You can download the library’s binaries or install it using NuGet.

PM> Install-Package Aspose.PDF

Create a Tagged PDF in C#

To create structure elements in a tagged PDF, Aspose.PDF for .NET provides the ITaggedContent interface. So let’s see how to use this interface to create a tagged PDF file in C#.

The following code sample shows how to create a tagged PDF in C#.

The following is the output of the above code sample.

Create a Tagged PDF File in C#

C# Create a Tagged PDF with Nested Elements

In the previous example, we created a simple tagged PDF that contains a paragraph. Let’s now have a look at how to add nested elements in a tagged PDF. The following are the steps to perform this operation.

The following code sample shows how to add nested elements in a tagged PDF in C#.

The following screenshot shows the tagged PDF with nested elements.

Create a Tagged PDF with Nested Elements in C#

Styling Text Structure in a Tagged PDF in C#

You can also apply styling to the text in a tagged PDF by setting font style, family, size, etc. For this, Aspose.PDF for .NET provides Font, FontSize, FontStyle and ForegroundColor properties of StructureTextState class. The following code sample shows how to apply text styling in a tagged PDF in C#.

C# Illustrating Structure Elements in a Tagged PDF

To illustrate the structure elements, Aspose.PDF for .NET provides IllustrationElement class. The following code sample shows how to use this class to illustrate the structural elements in a tagged PDF.

Free PDF Library to Create Tagged PDF

You can get a free temporary license and create tagged PDF files without evaluation limitations.

Explore C# PDF Library

Besides, you can explore more about the C# PDF library using the documentation. In case you would have any questions or queries, you can contact us via our forum.

Conclusion

In this article, you have learned how to create tagged PDF files in C#. Furthermore, you have seen how to create nested elements, apply styling to text, and illustrate structure elements in a tagged PDF programmatically.

See Also