Creating PDF/A compatible PDF in C# (.NET Core)

Creating PDFA compatible PDF using DynamicPDF Generator is simple and easy. DynamicPDF can produce and preserve PDF documents with the following conformance levels

  • PDF/A-1a
  • PDF/A-1b
  • PDF/A-2a
  • PDF/A-2b
  • PDF/A-2u
  • PDF/A-3a
  • PDF/A-3b
  • PDF/A-3u

How to create PDF/A compatible PDF in C#

Below are the steps and sample code to create PDF/A-1a and PDF/A-3a compatible PDF document using the Generator product.

Steps for Creating PDF/A compatible PDF Document

  1. Create a Document object.
  2. Create a XmpMetadata object.
  3. Create a PdfASchema object and specify the PDF/A standard (A-1a in this case).
  4. Create a DublinCoreSchema object and assign to XmpMetaData.
  5. Set the properties for DublinCoreSchema.
  6. Set the XmpMetadata to the Document.
  7. Create a IccProfile object.
  8. Create a OutputIntent object and specify the parameters along with the IccProfile object.
  9. Create a Page object and add any page element.
  10. Add Page to the Document.
  11. Save the PDf document.

Sample Code - C#

Document document = new Document();
document.Title = "PDF/A1 Document";

XmpMetadata xmp = new XmpMetadata();

PdfASchema pdfaschema = new PdfASchema(PdfAStandard.PDF_A_1a_2005);
xmp.AddSchema(pdfaschema);

DublinCoreSchema dc = xmp.DublinCore;
dc.Title.DefaultText = document.Title;
dc.Description.DefaultText = document.Subject;
dc.Creators.Add(document.Author);
dc.Title.AddLang("en-us", "PDF/A1 Document");
document.XmpMetadata = xmp;

IccProfile iccProfile = new IccProfile(@"C:\Temp\IccProfile\sRGB_IEC61966-2-1_noBPC.icc");
OutputIntent outputIntents = new OutputIntent("", "IEC 61966-2.1 Default RGB colour space - sRGB 1 ", "http://www.color.org", "sRGB IEC61966-2.1 1", iccProfile);
outputIntents.Version = OutputIntentVersion.PDF_A;
document.OutputIntents.Add(outputIntents);

string text = "PDF/A (Archiving) specifically targets PDF documents that need to be preserved long term.";
OpenTypeFont openTypeFont = new OpenTypeFont("times.ttf");
Label label = new Label(text, 0, 0, 504, 100, openTypeFont, 18, TextAlign.Center, RgbColor.BlueViolet);

Page page = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
page.Elements.Add(label);
document.Pages.Add(page);
            
document.Draw(@"C:\Output.pdf");        

Steps for Creating PDF/A-3a compatible PDF Document

  1. Create a Document object.
  2. Create a XmpMetadata object.
  3. Create a PdfASchema object and specify the PDF/A standard (A-3a in this case).
  4. Create a DublinCoreSchema object and assign to XmpMetaData.
  5. Set the properties for DublinCoreSchema.
  6. Set the XmpMetadata to the Document.
  7. Create a IccProfile object.
  8. Create a OutputIntent object and specify the parameters along with the IccProfile object.
  9. Create a EmbeddedFile object pass any file that needs to be embedded.
  10. Create a Page object and add any page element.
  11. Add Page to the Document.
  12. Save the PDf document.

Sample Code - C#

Document document = new Document();
document.Title = "PDF/A1 Document";

XmpMetadata xmp = new XmpMetadata();

PdfASchema pdfaschema = new PdfASchema(PdfAStandard.PdfA3a);
xmp.AddSchema(pdfaschema);

DublinCoreSchema dc = xmp.DublinCore;
dc.Title.DefaultText = document.Title;
dc.Description.DefaultText = document.Subject;
dc.Creators.Add(document.Author);
dc.Title.AddLang("en-us", "PDF/A1 Document");
document.XmpMetadata = xmp;

 // Needs iccprofile file to be embedded.
IccProfile iccProfile = new IccProfile(@"ProfilePath\sRGB_IEC61966-2-1_noBPC.icc");
OutputIntent outputIntents = new OutputIntent("", "IEC 61966-2.1 Default RGB colour space - sRGB 1 ", "http://www.color.org", "sRGB IEC61966-2.1 1", iccProfile);
outputIntents.Version = OutputIntentVersion.PDF_A;
document.OutputIntents.Add(outputIntents);

EmbeddedFile embeddedFile1 = new EmbeddedFile(@"ExcelFilePath\HelloWorldExcel.xls");
embeddedFile1.Relation = EmbeddedFileRelation.Data;
embeddedFile1.MimeType = "application/excel";
document.EmbeddedFiles.Add(embeddedFile1);
 
EmbeddedFile embeddedFile2 = new EmbeddedFile(@"XMLFilePath\Simple.xml");
embeddedFile2.Relation = EmbeddedFileRelation.Source;
embeddedFile2.MimeType = "application/xml";
document.EmbeddedFiles.Add(embeddedFile2);
 
string text = "PDF/A (Archiving) specifically targets PDF documents that need to be preserved long term.";
OpenTypeFont openTypeFont = new OpenTypeFont("times.ttf");
openTypeFont.Subset = false;
Label label = new Label(text, 0, 0, 504, 100, openTypeFont, 18, TextAlign.Center, RgbColor.BlueViolet);

Page page = new Page(PageSize.Letter, PageOrientation.Portrait, 54.0f);
page.Elements.Add(label);
document.Pages.Add(page);
            
document.Draw(@"C:\Output.pdf");        

Getting Started

NuGet Package

DynamicPDF Generator is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET package. The Core Suite package includes Generator, Merger and ReportWriter.

Nuget Logo
NuGet Package ID: ceTe.DynamicPDF.CoreSuite.NET

Example Project

An example project showing this functionality can be cloned or viewed from GitHub:

GitHub Logo
Clone or View Example Project on GitHub

DynamicPDF Generator Information

More information can be found here:

Available in other platforms

DynamicPDF Generator is available for the following platforms. Refer to the respective product pages for more details.

Why Choose DynamicPDF?

  • Transparent Pricing
  • Lots of Features
  • Easy to Use
  • Great Support
  • Efficient Performance
  • Product Maturity (Over 18 Years)
  • Free Evaluation
  • .NET Core Support (Most Products)
  • Flexible Licensing

We’re Not The Only Ones That Think We’re Great!