Create PDF/A documents with XFINIUM.PDF library

XFINIUM.PDF 6.6 brings support for PDF/A-2 and PDF/A-3. PDF/A (ISO 19005) is an ISO-standardized version of the PDF format specialized for use in the archiving and long-term preservation of electronic documents.

PDF/A-1B (part 1 of ISO 19005) was already supported, with v6.6 we add support for PDF/A-2 (ISO 19005 part 2) and PDF/A-3 (ISO 19005 part 3).
PDF/A-2 builds on top of PDF/A-1 and includes additional support for transparency, optional content and document attachments (the attachments must in PDF/A-1 format). PDF/A-3 builds on top of PDF/A-3 and allows all types of document attachments.
Both PDF/A-2 and PDF/A-3 have 3 conformance levels: A, B and U. XFINIUM.PDF supports conformance levels B and U for both PDF/A-2 and PDF/A-3.

The code below shows how to create a PDF/A-2B file.

PdfFixedDocument document = new PdfFixedDocument();
document.OptionalContentProperties = new PdfOptionalContentProperties();

// Setup the document by creating a PDF/A output intent, based on a RGB ICC profile, 
// and document information and metadata
PdfIccColorSpace icc = new PdfIccColorSpace();
icc.IccProfile = File.ReadAllBytes("rgb.icc");
PdfOutputIntent oi = new PdfOutputIntent();
oi.Type = PdfOutputIntentType.PdfA1;
oi.Info = "sRGB IEC61966-2.1";
oi.OutputConditionIdentifier = "Custom";
oi.DestinationOutputProfile = icc;
document.OutputIntents = new PdfOutputIntentCollection();
document.OutputIntents.Add(oi);

document.DocumentInformation = new PdfDocumentInformation();
document.DocumentInformation.Author = "XFINIUM Software";
document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-2B/U Demo";
document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-2B/U Demo";
document.DocumentInformation.Producer = "XFINIUM.PDF";
document.DocumentInformation.Keywords = "pdf/a";
document.DocumentInformation.Subject = "PDF/A-2B/U Sample produced by XFINIUM.PDF";
document.XmpMetadata = new PdfXmpMetadata();

PdfPage page = document.Pages.Add();
page.Rotation = 90;

// All fonts must be embedded in a PDF/A document.
PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
sao.Font = new PdfAnsiTrueTypeFont("verdana.ttf", 24, true);
sao.Brush = new PdfBrush(new PdfRgbColor(0, 0, 128));

PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
slo.VerticalAlign = PdfStringVerticalAlign.Bottom;
slo.X = page.Width / 2;
slo.Y = page.Height / 2 - 10;
page.Graphics.DrawString("XFINIUM.PDF", sao, slo);
slo.Y = page.Height / 2 + 10;
slo.VerticalAlign = PdfStringVerticalAlign.Top;
sao.Font.Size = 14;
page.Graphics.DrawString("This is a sample PDF/A-2B/U document that shows the PDF/A-2B/U capabilities in XFINIUM.PDF library", sao, slo);

// PDF/A-2 documents support optional content and transparency.
PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup();
ocgPage1.Name = "Green Rectangle";
page.Graphics.BeginOptionalContentGroup(ocgPage1);
page.Graphics.SaveGraphicsState();
PdfExtendedGraphicState gs = new PdfExtendedGraphicState();
gs.FillAlpha = 0.8;
gs.StrokeAlpha = 0.2;
gs.BlendMode = PdfBlendMode.Luminosity;
page.Graphics.SetExtendedGraphicState(gs);

PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen);
PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5);
page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40);

page.Graphics.RestoreGraphicsState();
page.Graphics.EndOptionalContentGroup();

// Build the display tree for the optional content, 
// how its structure and relationships between optional content groups are presented to the user.
PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1);
document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node);

PdfAFormatter.Save(document, "xfinium.pdf.sample.pdfa2b.pdf", PdfAFormat.PdfA2b);
Dim document As New PdfFixedDocument()
document.OptionalContentProperties = New PdfOptionalContentProperties()

' Setup the document by creating a PDF/A output intent, based on a RGB ICC profile, 
' and document information and metadata
Dim icc As New PdfIccColorSpace()
icc.IccProfile = File.ReadAllBytes("rgb.icc")
Dim oi As New PdfOutputIntent()
oi.Type = PdfOutputIntentType.PdfA1
oi.Info = "sRGB IEC61966-2.1"
oi.OutputConditionIdentifier = "Custom"
oi.DestinationOutputProfile = icc
document.OutputIntents = New PdfOutputIntentCollection()
document.OutputIntents.Add(oi)

document.DocumentInformation = New PdfDocumentInformation()
document.DocumentInformation.Author = "XFINIUM Software"
document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-2B/U Demo"
document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-2B/U Demo"
document.DocumentInformation.Producer = "XFINIUM.PDF"
document.DocumentInformation.Keywords = "pdf/a"
document.DocumentInformation.Subject = "PDF/A-2B/U Sample produced by XFINIUM.PDF"
document.XmpMetadata = New PdfXmpMetadata()

Dim page As PdfPage = document.Pages.Add()
page.Rotation = 90

' All fonts must be embedded in a PDF/A document.
Dim sao As New PdfStringAppearanceOptions()
sao.Font = New PdfAnsiTrueTypeFont(ttfInput, 24, True)
sao.Brush = New PdfBrush(New PdfRgbColor(0, 0, 128))

Dim slo As New PdfStringLayoutOptions()
slo.HorizontalAlign = PdfStringHorizontalAlign.Center
slo.VerticalAlign = PdfStringVerticalAlign.Bottom
slo.X = page.Width / 2
slo.Y = page.Height / 2 - 10
page.Graphics.DrawString("XFINIUM.PDF", sao, slo)
slo.Y = page.Height / 2 + 10
slo.VerticalAlign = PdfStringVerticalAlign.Top
sao.Font.Size = 14
page.Graphics.DrawString("This is a sample PDF/A-2B/U document that shows the PDF/A-2B/U capabilities in XFINIUM.PDF library", sao, slo)

' PDF/A-2 documents support optional content and transparency.
Dim ocgPage1 As New PdfOptionalContentGroup()
ocgPage1.Name = "Green Rectangle"
page.Graphics.BeginOptionalContentGroup(ocgPage1)
page.Graphics.SaveGraphicsState()
Dim gs As New PdfExtendedGraphicState()
gs.FillAlpha = 0.8
gs.StrokeAlpha = 0.2
gs.BlendMode = PdfBlendMode.Luminosity
page.Graphics.SetExtendedGraphicState(gs)

Dim greenBrush As New PdfBrush(PdfRgbColor.DarkGreen)
Dim bluePen As New PdfPen(PdfRgbColor.DarkBlue, 5)
page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40)

page.Graphics.RestoreGraphicsState()
page.Graphics.EndOptionalContentGroup()

' Build the display tree for the optional content, 
' how its structure and relationships between optional content groups are presented to the user.
Dim ocgPage1Node As New PdfOptionalContentDisplayTreeNode(ocgPage1)
document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node)

PdfAFormatter.Save(document, "xfinium.pdf.sample.pdfa2b.pdf", PdfAFormat.PdfA2b)

The code below shows how to create a PDF/A-3U file.

PdfFixedDocument document = new PdfFixedDocument();
document.OptionalContentProperties = new PdfOptionalContentProperties();

// Setup the document by creating a PDF/A output intent, based on a RGB ICC profile, 
// and document information and metadata
PdfIccColorSpace icc = new PdfIccColorSpace();
byte[] profilePayload = new byte[iccInput.Length];
iccInput.Read(profilePayload, 0, profilePayload.Length);
icc.IccProfile = File.ReadAllBytes("rgb.icc");
PdfOutputIntent oi = new PdfOutputIntent();
oi.Type = PdfOutputIntentType.PdfA1;
oi.Info = "sRGB IEC61966-2.1";
oi.OutputConditionIdentifier = "Custom";
oi.DestinationOutputProfile = icc;
document.OutputIntents = new PdfOutputIntentCollection();
document.OutputIntents.Add(oi);

document.DocumentInformation = new PdfDocumentInformation();
document.DocumentInformation.Author = "XFINIUM Software";
document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-3B/U Demo";
document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-3B/U Demo";
document.DocumentInformation.Producer = "XFINIUM.PDF";
document.DocumentInformation.Keywords = "pdf/a";
document.DocumentInformation.Subject = "PDF/A-3B/U Sample produced by XFINIUM.PDF";
document.XmpMetadata = new PdfXmpMetadata();

PdfPage page = document.Pages.Add();
page.Rotation = 90;

// All fonts must be embedded in a PDF/A document.
PdfStringAppearanceOptions sao = new PdfStringAppearanceOptions();
sao.Font = new PdfAnsiTrueTypeFont(ttfInput, 24, true);
sao.Brush = new PdfBrush(new PdfRgbColor(0, 0, 128));

PdfStringLayoutOptions slo = new PdfStringLayoutOptions();
slo.HorizontalAlign = PdfStringHorizontalAlign.Center;
slo.VerticalAlign = PdfStringVerticalAlign.Bottom;
slo.X = page.Width / 2;
slo.Y = page.Height / 2 - 10;
page.Graphics.DrawString("XFINIUM.PDF", sao, slo);
slo.Y = page.Height / 2 + 10;
slo.VerticalAlign = PdfStringVerticalAlign.Top;
sao.Font.Size = 14;
page.Graphics.DrawString("This is a sample PDF/A-3B/U document that shows the PDF/A-3B/U capabilities in XFINIUM.PDF library", sao, slo);

// PDF/A-3 documents support optional content and transparency.
PdfOptionalContentGroup ocgPage1 = new PdfOptionalContentGroup();
ocgPage1.Name = "Green Rectangle";
page.Graphics.BeginOptionalContentGroup(ocgPage1);
page.Graphics.SaveGraphicsState();
PdfExtendedGraphicState gs = new PdfExtendedGraphicState();
gs.FillAlpha = 0.8;
gs.StrokeAlpha = 0.2;
gs.BlendMode = PdfBlendMode.Luminosity;
page.Graphics.SetExtendedGraphicState(gs);

PdfBrush greenBrush = new PdfBrush(PdfRgbColor.DarkGreen);
PdfPen bluePen = new PdfPen(PdfRgbColor.DarkBlue, 5);
page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40);

page.Graphics.RestoreGraphicsState();
page.Graphics.EndOptionalContentGroup();

// Build the display tree for the optional content, 
// how its structure and relationships between optional content groups are presented to the user.
PdfOptionalContentDisplayTreeNode ocgPage1Node = new PdfOptionalContentDisplayTreeNode(ocgPage1);
document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node);

// PDF/A-3 files also support document attachments.
// Include the TrueType font as an attachment.
byte[] ttfData = File.ReadAllBytes("verdana.ttf");
PdfDocumentFileAttachment att = new PdfDocumentFileAttachment(ttfData);
att.FileName = "verdana.ttf";
att.Description = "Verdana Regular";
att.MimeType = "application/octet-stream";
document.FileAttachments.Add(att);

PdfAFormatter.Save(document, "xfinium.pdf.sample.pdfa3u.pdf", PdfAFormat.PdfA3u);
Dim document As New PdfFixedDocument()
document.OptionalContentProperties = New PdfOptionalContentProperties()

' Setup the document by creating a PDF/A output intent, based on a RGB ICC profile, 
' and document information and metadata
Dim icc As New PdfIccColorSpace()
icc.IccProfile = File.ReadAllBytes("rgb.icc")
Dim oi As New PdfOutputIntent()
oi.Type = PdfOutputIntentType.PdfA1
oi.Info = "sRGB IEC61966-2.1"
oi.OutputConditionIdentifier = "Custom"
oi.DestinationOutputProfile = icc
document.OutputIntents = New PdfOutputIntentCollection()
document.OutputIntents.Add(oi)

document.DocumentInformation = New PdfDocumentInformation()
document.DocumentInformation.Author = "XFINIUM Software"
document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-3B/U Demo"
document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-3B/U Demo"
document.DocumentInformation.Producer = "XFINIUM.PDF"
document.DocumentInformation.Keywords = "pdf/a"
document.DocumentInformation.Subject = "PDF/A-3B/U Sample produced by XFINIUM.PDF"
document.XmpMetadata = New PdfXmpMetadata()

Dim page As PdfPage = document.Pages.Add()
page.Rotation = 90

' All fonts must be embedded in a PDF/A document.
Dim sao As New PdfStringAppearanceOptions()
sao.Font = New PdfAnsiTrueTypeFont(ttfInput, 24, True)
sao.Brush = New PdfBrush(New PdfRgbColor(0, 0, 128))

Dim slo As New PdfStringLayoutOptions()
slo.HorizontalAlign = PdfStringHorizontalAlign.Center
slo.VerticalAlign = PdfStringVerticalAlign.Bottom
slo.X = page.Width / 2
slo.Y = page.Height / 2 - 10
page.Graphics.DrawString("XFINIUM.PDF", sao, slo)
slo.Y = page.Height / 2 + 10
slo.VerticalAlign = PdfStringVerticalAlign.Top
sao.Font.Size = 14
page.Graphics.DrawString("This is a sample PDF/A-3B/U document that shows the PDF/A-3B/U capabilities in XFINIUM.PDF library", sao, slo)

' PDF/A-3 documents support optional content and transparency.
Dim ocgPage1 As New PdfOptionalContentGroup()
ocgPage1.Name = "Green Rectangle"
page.Graphics.BeginOptionalContentGroup(ocgPage1)
page.Graphics.SaveGraphicsState()
Dim gs As New PdfExtendedGraphicState()
gs.FillAlpha = 0.8
gs.StrokeAlpha = 0.2
gs.BlendMode = PdfBlendMode.Luminosity
page.Graphics.SetExtendedGraphicState(gs)

Dim greenBrush As New PdfBrush(PdfRgbColor.DarkGreen)
Dim bluePen As New PdfPen(PdfRgbColor.DarkBlue, 5)
page.Graphics.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40)

page.Graphics.RestoreGraphicsState()
page.Graphics.EndOptionalContentGroup()

' Build the display tree for the optional content, 
' how its structure and relationships between optional content groups are presented to the user.
Dim ocgPage1Node As New PdfOptionalContentDisplayTreeNode(ocgPage1)
document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node)

' PDF/A-3 files also support document attachments.
' Include the TrueType font as an attachment.
Dim ttfData As Byte() = File.ReadAllBytes("verdana.ttf")
Dim att As New PdfDocumentFileAttachment(ttfData)
att.FileName = "verdana.ttf"
att.Description = "Verdana Regular"
att.MimeType = "application/octet-stream"
document.FileAttachments.Add(att)

PdfAFormatter.Save(document, "xfinium.pdf.sample.pdfa3u.pdf", PdfAFormat.PdfA3u)

Latest version of XFINIUM.PDF library can be downloaded here.

2 thoughts on “Create PDF/A documents with XFINIUM.PDF library”

    1. Yes, after you finished creating the PdfFlowDocument you can retrieve the inner PdfFixedDocument (PdfFlowDocument.GetFixedDocument) and then save the PdfFixedDocument in PDF/A format.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: