Create Accessible PDF Documents Using C# | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (217)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (917)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (148)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (629)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (593)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Create Accessible PDF Documents Using C#

Create Accessible PDF Documents Using C#

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, you can easily create a tagged PDF document that is compatible with Web Content Accessibility Guidelines (WCAG) 2.0 (ISO/IEC 40500:2012) and the PDF/UA (ISO 14289-1) standard.

In this blog, we will cover the following:

Transform your PDF files effortlessly in C# with just five lines of code using Syncfusion's comprehensive PDF Library!

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.

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.

Let’s create an accessible PDF.

Step 1: Install the Syncfusion.Pdf.Net.Core NuGet package as a reference to your .NET applications from nuget.org.
Installing PDF.NET Core NuGet

Step 2: Use the PdfStructureElement class to create and set tags to the PDF elements, and set the different types of tags using the PdfTagType enum.

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

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#Note: For more information about adding different tags in the PDF document, refer to the working with a 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.

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

Boost your productivity with Syncfusion's PDF Library! Gain access to invaluable insights and tutorials in our extensive documentation.

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.

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

See a world of document processing possibilities in Syncfusion's PDF Library as we unveil its features in interactive demonstrations.

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 and Syncfusion.DocIORenderer.Net.Core NuGet packages as references to your .NET applications from nuget.org.

Installing PDF.NET.Core and DocIO Renderer.NET.Core NuGetStep 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.

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

GitHub reference

Also, you can find all the examples for creating accessible PDF in the GitHub repository.

Join thousands of developers who rely on Syncfusion for their PDF needs. Experience the difference today!

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 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, support portal, or feedback portal. We are happy to assist you!

If you like this article, we think you will also like the following articles about PDF Library:

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed