Cracking the Code: Document Conversion to Meet PDF Standards

Cracking the Code: Document Conversion to Meet PDF Standards

Published January 18, 2023

Standard formats for PDF were created to define quality requirements that ensure interoperability and simplify compliance. ISO defined these standards to guarantee reliable PDF processing for the many PDF creation programs that exist. In the Adobe PDF Library, we have several ways to convert your documents into PDFs that meet ISO standards, including PDF/A for archiving and PDF/X for printing. Let’s take a look at a few of the code samples in APDFL that demonstrate how those conversions work.

Note that the code samples discussed here are in .NET, but we have more available in .NET Framework, C++, Java/Maven, Kotlin, and VB.NET.

PDF/A for Long-Term Archiving

PDF/A was first published in late 2005 as ISO 19005-1. Businesses and public institutions benefit from PDF/A because digital documents can be archived permanently using this standard. While the format was initially used as a replacement for scanned paper or TIFFs in archives, it is now also used predominantly for digitally created documents (source: PDF Association). 

PDFAConverter is a code sample that converts a PDF document to a PDF/A compliant document. If you’re familiar with PFD/A, you know that there are different levels, depending on the type of compliance you need (PDF/A-1, 2, 3, etc.)


namespace PDFAConverter
{
class PDFAConverter
{
static void Main(string[] args)
{
Console.WriteLine("PDFAConverter Sample:");


// ReSharper disable once UnusedVariable
using (Library lib = new Library())
{
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/ducky.pdf";
String sOutput = "PDFAConverter-out.pdf";

if (args.Length > 0)
sInput = args[0];

if (args.Length > 1)
sOutput = args[1];

Console.WriteLine("Converting " + sInput + ", output file is " + sOutput);

using (Document doc = new Document(sInput))
{
// Make a conversion parameters object
PDFAConvertParams pdfaParams = new PDFAConvertParams();
pdfaParams.AbortIfXFAIsPresent = true;
pdfaParams.IgnoreFontErrors = false;
pdfaParams.NoValidationErrors = false;
pdfaParams.ValidateImplementationLimitsOfDocument = true;

// Create a PDF/A compliant version of the document
PDFAConvertResult pdfaResult = doc.CloneAsPDFADocument(PDFAConvertType.RGB3b, pdfaParams);

// The conversion may have failed: we must check if the result has a valid Document
if (pdfaResult.PDFADocument == null)
{
Console.WriteLine("ERROR: Could not convert " + sInput + " to PDF/A.");
}
else
{
Console.WriteLine("Successfully converted " + sInput + " to PDF/A.");

Document pdfaDoc = pdfaResult.PDFADocument;

//Save the result.
pdfaDoc.Save(pdfaResult.PDFASaveFlags, sOutput);
}

ZUGFeRD Standard for Invoice Archiving 

ZUGFeRD is an invoice standard based on PDF/A-3 plus XML data. It has been experiencing a surge in interest over the past few years, and there is a big push for governments to use it to standardize their invoicing systems. 

The ConvertToZUGFeRD sample converts a PDF document and an Invoice XML document to a ZUGFeRD compliant PDF document. This sample program illustrates how to easily convert a PDF document to PDF/A-3, how to add the ZUGFeRD XML invoice as an attachment to the document, and how to add the metadata entries unique to ZUGFeRD and the required extension, which are not part of the PDF/A-3 standard itself.

Are you prepared for the 2025 ZUGFeRD updates? Read PDFs and the ZUGFeRD Standard: A Comprehensive Guide to Compliance


PDF/X – Standard for the Printing Industry

In the printing and prepress sector, PDF files are the “raw material” from which printing is done. The industry formulated corresponding requirements shortly after PDF’s existence and developed PDF/X (“X” stands for “eXchange”) under the umbrella of ISO. The purpose of PDF/X is to facilitate graphics exchange, and it, therefore, has a series of printing-related requirements which do not apply to standard PDF files. 

The PDFXConverter sample converts a PDF document to a PDF/X compliant document.

namespace PDFXConverter
{
class PDFXConverter
{
static void Main(string[] args)
{
Console.WriteLine("PDFXConverter Sample:");


using (Library lib = new Library())
{
Console.WriteLine("Initialized the library.");

String sInput = Library.ResourceDirectory + "Sample_Input/sample.pdf";
String sOutput = "../PDFXConverter-out.pdf";

if (args.Length > 0)
sInput = args[0];

if (args.Length > 1)
sOutput = args[1];

Console.WriteLine("Input file: " + sInput + ". Writing to output " + sOutput);

using (Document doc = new Document(sInput))
{
// Make a conversion parameters object
PDFXConvertParams pdfxParams = new PDFXConvertParams();

// Create a PDF/X compliant version of the document
PDFXConvertResult pdfxResult = doc.CloneAsPDFXDocument(PDFXConvertType.X4, pdfxParams);

// The conversion may have failed, we must check if the result has a valid Document.
if (pdfxResult.PDFXDocument == null)
Console.WriteLine("ERROR: Could not convert " + sInput + " to PDF/X.");
else
{
Console.WriteLine("Successfully converted " + sInput + " to PDF/X.");

Document pdfxDoc = pdfxResult.PDFXDocument;

// Set the SaveFlags returned in the PDFConvertResult.
pdfxDoc.Save(pdfxResult.PDFXSaveFlags, sOutput);
}

We invite you to check out the Datalogics GitHub Repository for more information on Adobe PDF Library and samples for the creation, modification and management of PDF documents.

Streamline your PDF Development Workflow 

Start a free trial and discover how our PDF SDK can minimize your development time.