Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (161).NET Core  (29).NET MAUI  (63)Angular  (74)ASP.NET  (50)ASP.NET Core  (79)ASP.NET MVC  (88)Azure  (36)Blazor  (152)DocIO  (23)Essential JS 2  (84)Essential Studio  (172)File Formats  (28)Flutter  (123)JavaScript  (186)Microsoft  (113)PDF  (67)React  (61)Succinctly series  (128)Syncfusion  (609)TypeScript  (31)Uno Platform  (3)UWP  (4)Vue  (39)Webinar  (35)Windows Forms  (59)WinUI  (52)WPF  (138)Xamarin  (155)XlsIO  (25)Other CategoriesBarcode  (5)BI  (29)Bold BI  (5)Build conference  (6)Business intelligence  (54)Button  (4)C#  (119)Chart  (57)Cloud  (12)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (6)DataGrid  (55)Development  (394)Doc  (7)DockingManager  (1)eBook  (96)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (23)Extensions  (18)File Manager  (4)Gantt  (11)Gauge  (11)Git  (4)Grid  (28)HTML  (10)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (311)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (30)Performance  (9)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (7)Road Map  (10)Scheduler  (36)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (22)Solution Services  (3)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (11)Tips and Tricks  (92)UI  (224)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (23)Visual Studio Code  (16)Web  (371)What's new  (213)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
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:

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

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

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

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:

Share on twitter
Share on facebook
Share on linkedin
Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top