DEV Community

Atir Tahir
Atir Tahir

Posted on

How to convert a PDF to PDF/A using C#

What is a PDF/A file format, how does it differ from PDF?

The core difference between PDF and PDF/A is, a PDF/A document can be preserved for a long time. Let's understand the difference with some examples. PDF is unsuitable for long-term use because it uses font (or other resource) linking instead of font embedding.
Any resource (e.g. font, image, clip-art) that is added in the PDF/A will always be available because it doesn't allow the file to reference the external resources. In order to make sure the resource is always available, they are embedded, not linked or refered.
Don't forget that PDF/A is basically a subset of PDF.

PDF to PDF/A conversion

From this difference, you can observe how appropriate it is to use a PDF/A. For any paperless company or firm, this difference is quite practical. There are a lot of online utilities/tools that provide an option or feature to convert a PDF to PDF/A. But here the big concern is security or document confidentiality. In such a condition, you may prefer your own conversion tool.

Stand-alone document conversion API

When document confidentiality is concerned you may not rely on any third party software or tools. Hence, in this blog we'll explore a stand-alone API that could be integrated in your existing or new .NET applciation without any framework or platform dependency.

Let's have a look at PDF to PDF/A conversion code,

using (var converter = new Converter(@"D:/sample.pdf"))   
{   
    var options = new PdfConvertOptions();   
    options.PdfOptions.PdfFormat = PdfFormats.PdfA_3A;   
    converter.Convert(@"D:/output.pdf",options);   
}
Enter fullscreen mode Exit fullscreen mode

PdfFormats class has following static members,

  • PdfA_1A
  • PdfA_1B
  • PdfA_2A
  • PdfA_2B
  • PdfA_2U
  • PdfA_3A
  • PdfA_3B
  • PdfA_3U
  • PdfX_1A
  • PdfX_3

All you have to do is to add this DLL reference (download latest version) in your new or existing .NET project. In case of any issue or feature details/information, you can post here.

Top comments (0)