Create Tagged PDF Files in C# .NET

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# .NET API to Create Tagged PDF Files

Aspose.PDF for .NET is a robust API for PDF generation and manipulation within the .NET applications. Using the API, you can seamlessly create, process, and convert PDF files of simple and complex layouts. You can download the API’s binaries or install it using NuGet.

PM> Install-Package Aspose.PDF

Create a Tagged PDF File 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#

Create a Tagged PDF with Nested Elements in C#

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

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 FontFontSizeFontStyle and ForegroundColor properties of StructureTextState class. The following code sample shows how to apply text styling in a tagged PDF in C#.

Illustrating Structure Elements in a Tagged PDF in C#

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 structure elements in a tagged PDF.

Get a Free License

You can get a free temporary license in order to use Aspose.PDF for .NET without evaluation limitations.

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. Besides, you can explore more about .NET PDF API using the documentation. In case you would have any questions or queries, you can contact us via our forum.

See Also