Create Accessible PDF Documents Using C#
Tags: csharp, dotnet, pdf, a11y
Published: 2022-05-04 12:13:55

---
title: Create Accessible PDF Documents Using C#
published: true
date: 2022-05-04 10:00:07 UTC
tags: csharp, dotnet, pdf, accessibility
canonical_url: https://www.syncfusion.com/blogs/post/create-accessible-pdf-documents-using-c.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yzw5cirxp1say5vplr14.png
---

Adding tags to the elements of a PDF document makes it accessible. When a tagged PDF document has accessibility tags, it is useful for screen readers and other assistive technologies to read and navigate the document.

With the help of the [Syncfusion PDF Library](https://www.syncfusion.com/document-processing/pdf-framework/net "Syncfusion PDF Library"), you can easily create a tagged PDF document that is compatible with [Web Content Accessibility Guidelines](https://www.w3.org/TR/WCAG20/ "Web Content Accessibility Guidelines") (WCAG) 2.0 ([ISO/IEC 40500:2012](https://www.iso.org/standard/58625.html "ISO/IEC 40500:2012")) and the [PDF/UA (ISO 14289-1)](https://www.iso.org/standard/54564.html "PDF/UA (ISO 14289-1)") standard.

In this blog, we will cover the following:

- [What is an accessibility tag?](#accessibility-tag)
- [Create a simple accessible PDF](#create-accessible-pdf).
- [Auto-tagging a new PDF document](#auto-tagging-a-new-PDF).
- [Create a PDF conformance document with accessibility tags](#create-PDF-conformance-document-with-accessibility-tags).
- [Convert a Word document to a tagged PDF](#convert-word-to-tagged-pdf).

## What is an accessibility tag?

Accessibility tags give semantic meaning to PDF elements so that assistive technology can automatically recognize them.

Accessibility tags have names similar to HTML tags. You can find the list of standard tags in the [standard PDF tags documentation](https://helpx.adobe.com/in/acrobat/using/editing-document-structure-content-tags.html#standard_pdf_tags "Edit document structure with the Content and Tags panels").

Though these tags are embedded within the PDF document, they won’t make any visual differences. These tags define the structure of the PDF elements so that they are easily recognized by a screen reader or other text-to-speech software.

## Create a simple accessible PDF

A PDF document has many visual elements such as text, lists, images, and tables. These elements can be tagged using standard PDF tags. For more details on the tags that can added using Syncfusion PDF Library, refer to the [supported PDF tags class reference](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfTagType.html "Enum PdfTagType of .NET PDF Library").

Let’s create an accessible PDF.

**Step**  **1** : Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/ "Syncfusion.Pdf.Net.Core NuGet package") NuGet package as a reference to your .NET applications from nuget.org.  
 ![Installing PDF.NET Core NuGet](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Installing-PDF.NET-Core-NuGet.png)

**Step**  **2** : Use the [PdfStructureElement](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfStructureElement.html "Class PdfStructureElement of .NET PDF Library") class to create and set tags to the PDF elements, and set the different types of tags using the [PdfTagType](https://help.syncfusion.com/cr/file-formats/Syncfusion.Pdf.PdfTagType.html "PdfTagType of .NET PDF Library") enum.

Refer to the following code example to create a PDF document with a structure element.

```csharp
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

//Create new PDF document
using (PdfDocument doc = new PdfDocument())
{

  //Set the document title
  doc.DocumentInformation.Title = "PdfTextElement";

  //Create a new page
  PdfPage page = doc.Pages.Add();

  //Initialize the structure element with tag type paragraph
  PdfStructureElement structureElement = new PdfStructureElement(PdfTagType.Paragraph);

  //Represents the text that is the exact replacement for PdfTextElement
  structureElement.ActualText = "Simple paragraph element";

  string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European, and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

  //Initialize the PDF text element
  PdfTextElement element = new PdfTextElement(text);

  //Adding tag to the text element
  element.PdfTag = structureElement;

  //Create font for the text element
  element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);

  element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));

  //Draw text element with tag
  element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200));

  FileStream output = new FileStream("TaggedPDF.pdf", FileMode.CreateNew);

  //Save the document
  doc.Save(output);

}
```

By executing this code example, you will get a PDF document similar to the following screenshot.  
 ![Accessible PDF created using C#](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Accessible-PDF-created-using-C-Sharp.png) **Note:** For more information about adding different tags in the PDF document, refer to the [working with a tagged PDF documentation](https://help.syncfusion.com/file-formats/pdf/working-with-tagged-pdf "Working with Tagged PDF documentation").

## Auto-tagging a new PDF document

The Syncfusion PDF Library provides an auto-tag feature to automatically tag PDF elements with the appropriate tag types.

This feature helps users to easily convert regular PDFs to accessible PDF documents.

Here is the same code used in the previous section with auto-tagging enabled.

```csharp
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

using (PdfDocument doc = new PdfDocument())
{

  //Enable auto-tagging
  doc.AutoTag = true;

  //Set the document title
  doc.DocumentInformation.Title = "PdfTextElement";

  //Create new page
  PdfPage page = doc.Pages.Add();

  string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

  //Initialize the PDF text element
  PdfTextElement element = new PdfTextElement(text);

  //Create font for the text element
  element.Font = new PdfStandardFont(PdfFontFamily.TimesRoman, 12);

  element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));

  //Draw text element with tag
  element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200));

  FileStream output = new FileStream("Auto-tagging.pdf", FileMode.CreateNew);

  //Save the document
  doc.Save(output);
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![Accessible PDF created using auto tagging feature](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Accessible-PDF-created-using-auto-tagging-feature.png)

## Create a PDF conformance document with accessibility tags

PDF/A is a PDF conformance format that helps in archiving, long-term preservation, and exchange of electronic documents.

PDF/A-3a is the conformance level to create an accessible PDF document.

The following code demonstrates the creation of a PDF/A-3a document.

```csharp
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;

//Create new PDF document
using (PdfDocument doc = new PdfDocument(PdfConformanceLevel.Pdf_A3A))
{

  //Enable auto-tagging
  doc.AutoTag = true;

  //Set the document title
  doc.DocumentInformation.Title = "PDF conformance";

  //Create new page
  PdfPage page = doc.Pages.Add();

  string text = "Adventure Works Cycles, the fictitious company on which the AdventureWorks sample databases are based, is a large, multinational manufacturing company. The company manufactures and sells metal and composite bicycles to North American, European and Asian commercial markets. While its base operation is located in Washington with 290 employees, several regional sales teams are located throughout their market base.";

  //Initialize the PDF text element
  PdfTextElement element = new PdfTextElement(text);

  FileStream fontStream = new FileStream("Arial.ttf", FileMode.Open, FileAccess.Read);

  PdfFont font = new PdfTrueTypeFont(fontStream, 14);

  //Create font for the text element
  element.Font = font;

  element.Brush = new PdfSolidBrush(new PdfColor(89, 89, 93));

  //Draw text element with tag
  element.Draw(page, new RectangleF(0, 0, page.Graphics.ClientSize.Width, 200));

  FileStream output = new FileStream("PDFA3a.pdf", FileMode.CreateNew);

  //Save the document
  doc.Save(output);
}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![Accessible PDF with PDF Conformance](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Accessible-PDF-with-PDF-Conformance.png)

## Convert a Word document to a tagged PDF

Microsoft Word documents are one of the most widely used file formats to edit and exchange content. With the help of the Syncfusion Word-to-PDF converter, you can easily convert any Word document to a PDF with accessibility tags. Here’s how to do it:

**Step 1** : Install the [Syncfusion.Pdf.Net.Core](https://www.nuget.org/packages/Syncfusion.Pdf.Net.Core/ "Syncfusion.Pdf.Net.Core NuGet package") and [Syncfusion.DocIORenderer.Net.Core](https://www.nuget.org/packages/Syncfusion.DocIORenderer.Net.Core/ "Syncfusion.DocIORenderer.Net.Core NuGet package") NuGet packages as references to your .NET applications from nuget.org.

**![Installing PDF.NET.Core and DocIO Renderer.NET.Core NuGet](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Installing-PDF.NET_.Core-and-DocIO-Renderer.NET_.Core-NuGet.png)Step 2**: Enable the **AutoTag** property in the settings to tag the PDF document while converting it.

The following code converts a Word document to a tagged PDF.

```csharp
using Syncfusion.DocIO.DLS;
using Syncfusion.DocIORenderer;
using Syncfusion.Pdf;

//Opens the file as a stream
FileStream docStream = new FileStream(@"../../../DocToPDF.docx", FileMode.Open, FileAccess.Read);

//Loads file stream into Word document
using (WordDocument wordDocument = new WordDocument(docStream, Syncfusion.DocIO.FormatType.Automatic))
{

  using (DocIORenderer render = new DocIORenderer())
  {

    //Sets true to preserve document-structured tags in the converted PDF document

    render.Settings.AutoTag = true;

    //Converts Word document into PDF document

    PdfDocument pdfDocument = render.ConvertToPDF(wordDocument);

    //Saves the PDF file
    FileStream outputStream = new FileStream("output.pdf", FileMode.CreateNew);

    pdfDocument.Save(outputStream);

    //Closes the instance of PDF document object

    pdfDocument.Close(true);
  }

}
```

By executing this code example, you will get a PDF document similar to the following screenshot.

![Accessible PDF created from Word document](https://www.syncfusion.com/blogs/wp-content/uploads/2022/05/Accessible-PDF-created-from-Word-document.png)

## Conclusion

In this blog post, we have walked through the steps to create a tagged PDF document, convert a regular PDF to a tagged PDF, enable auto-tagging, create PDF/A-3a documents, and convert a Word document to an accessible PDF in C# using the Syncfusion PDF Library.

Take a moment to peruse our [documentation](https://help.syncfusion.com/file-formats/pdf/working-with-tagged-pdf "Working with Tagged PDF document using .NET PDF Library") where you’ll find other options and features, all with accompanying code examples.

If you have any questions about these features, please let us know in the comments section below. You can also contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion support forum"), [support portal](https://www.syncfusion.com/support/directtrac "Syncfusion support portal"), or [feedback portal](https://www.syncfusion.com/feedback/pdf "Syncfusion Feedback Portal"). We are happy to assist you!