Creating PDF/A compatible PDF (.NET Core/Framework)
Creating PDFA compatible PDF using DynamicPDF Core Suite is straightforward.
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 DynamicPDF Core Suite.
Steps for Creating PDF/A Compatible PDF Document
- Create a
Document
object. - Create a
XmpMetadata
object. - Create a
PdfASchema
object and specify the PDF/A standard (A-1a in this case). - Create a
DublinCoreSchema
object and assign toXmpMetadata
. - Set the properties for
DublinCoreSchema
. - Set the XmpMetadata to the Document instance.
- Create a
IccProfile
object. - Create a
OutputIntent
object and specify the parameters along with theIccProfile
object. - Create a
Page
object and add any page element. - Add the Page instance to the Document instance.
- 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(@"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(@"Output.pdf");
Steps for Creating PDF/A-3a compatible PDF Document
- Create a
Document
object. - Create a
XmpMetadata
object. - Create a
PdfASchema
` object and specify the PDF/A standard (A-3a in this case). - Create a
DublinCoreSchema
object and assign toXmpMetadata
. - Set the properties for
DublinCoreSchema
. - Set the
XmpMetadata
to theDocument
. - Create a
IccProfile
object. - Create a
OutputIntent
object and specify the parameters along with theIccProfile
object. - Create a
EmbeddedFile
object pass any file that needs to be embedded. - Create a
Page
object and add any page element. - Add
Page
to the Document. - 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(@"Output.pdf");
Getting Started
NuGet Package
DynamicPDF Core Suite is available on NuGet and is part of the ceTe.DynamicPDF.CoreSuite.NET
package. The easiest way to install the package is through the Visual Studio Package Manager. You can also download the package directly from NuGet.
DynamicPDF Core Suite Information
More information can be found on the DynamicPDF Core Suite webpage.
Available on Other Platforms
DynamicPDF Core Suite is available for the Java and COM/ActiveX platforms. Refer to the respective product pages for more details.
- Java - DynamicPDF Generator for Java
- COM/ActiveX - DynamicPDF Generator for COM/ActiveX