Spire.PDF provides developers two methods to detect if a PDF file is PDF/A. The one is to use PdfDocument.Conformance property, the other is to use PdfDocument.XmpMetaData property. The following examples demonstrate how we can detect if a PDF file is PDF/A using these two methods.
Below is the screenshot of the sample file we used for demonstration:
Using PdfDocument.Conformance
using Spire.Pdf; using System; namespace Detect { class Program { static void Main(string[] args) { //Initialize a PdfDocument object PdfDocument pdf = new PdfDocument(); //Load the PDF file pdf.LoadFromFile("Example.pdf"); //Get the conformance level of the PDF file PdfConformanceLevel conformance = pdf.Conformance; Console.WriteLine("This PDF file is " + conformance.ToString()); } } }
Output:
Using PdfDocument.XmpMetaData
using Spire.Pdf; using Spire.Pdf.Xmp; using System; using System.Xml; namespace Detect { class Program { static void Main(string[] args) { //Initialize a PdfDocument object PdfDocument pdf = new PdfDocument(); //Load the PDF file pdf.LoadFromFile("Example.pdf"); //Get the XMP MetaData of the file XmpMetadata xmpData = pdf.XmpMetaData; //Get the XMP MetaData in XML format XmlDocument xmlData = xmpData.XmlData; string s = xmlData.InnerXml; Console.WriteLine(s); } } }
Output:
From the following output, we can see there is an XML tag named pdfaid:part and another XML tag named pdfaid:conformance. The PDF/A specification indicates that pdfaid:part references the PDF/A version identifier, and pdfaid:conformance references the PDF/A conformance level (A or B in case of PDF/A-1). In this example, the PDF/A version is 1 and the PDF/A conformance level is A. That is to say, this file is PDF/A-1a.