Validate PDF/A in C#
PDF/A documents are intended for long-term preservation, and their structure follows clear requirements. To determine if these structural requirements are met, validate the PDF/A document.
Validating a PDF/A document
To validate if a document is PDF/A-compliant, follow the steps below:
- Create a
GdPicturePDF
object. - Load the source document by passing its path to the
LoadFromFile
method. - Validate the document by calling the
IsValidPDFA
method. - Write the output to the console.
- Release unnecessary resources by calling the
CloseDocument
method.
using GdPicturePDF gdpicturePDF = new GdPicturePDF();// Load the source document.gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");// Validate the document.bool isValid = gdpicturePDF.IsValidPDFA();// Write the output to the console.Console.WriteLine(isValid);// Release unnecessary resources.gdpicturePDF.CloseDocument();
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() ' Load the source document. gdpicturePDF.LoadFromFile("C:\temp\source.pdf") ' Validate the document. Dim isValid As Boolean = gdpicturePDF.IsValidPDFA() ' Write the output to the console. Console.WriteLine(isValid) ' Release unnecessary resources. gdpicturePDF.CloseDocument()End Using
Used methods
Related topics
Validating a PDF/A document with detailed XML output
To validate if a document is PDF/A-compliant and receive all the validation details in XML format, follow these steps:
- Create a
GdPicturePDF
object. - Load the source document by passing its path to the
LoadFromFile
method. - Create an empty string and an empty Boolean to store the validation results.
- Validate the document by passing the empty string and the empty Boolean as reference parameters to the
IsValidPDFA
method. - Write the output to the console.
- Release unnecessary resources by calling the
CloseDocument
method.
using GdPicturePDF gdpicturePDF = new GdPicturePDF();// Load the source document.gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");// Create an empty string and an empty Boolean to store the validation results.string report = "";PdfValidationConformance conformance = new();// Validate the document.gdpicturePDF.IsValidPDFA(ref report, ref conformance);// Write the output to the console.string output = $"Verified Conformance:\n{conformance}\nValidation Report:\n{report}";Console.WriteLine(output);// Release unnecessary resources.gdpicturePDF.CloseDocument();
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() ' Load the source document. gdpicturePDF.LoadFromFile("C:\temp\source.pdf") ' Create an empty string and an empty Boolean to store the validation results. Dim report = "" Dim conformance As PdfValidationConformance = New PdfValidationConformance() ' Validate the document. gdpicturePDF.IsValidPDFA(report, conformance) ' Write the output to the console. Dim output = $"Verified Conformance: {conformance} Validation Report: {report}" Console.WriteLine(output) ' Release unnecessary resources. gdpicturePDF.CloseDocument()End Using
Used methods
Related topics
Validating a PDF/A document with detailed JSON output
To validate if a document is PDF/A-compliant and receive all the validation details in JSON format, follow the steps below:
- Create a
GdPicturePDF
object. - Load the source document by passing its path to the
LoadFromFile
method. - Create an empty string and an empty Boolean to store the validation results.
- Validate the document by passing the empty string and the empty Boolean as reference parameters to the
IsValidPDFA
method. - Convert the validation report to JSON format with the
XmlDocument
class. - Write the output to the console.
- Release unnecessary resources by calling the
CloseDocument
method.
using GdPicturePDF gdpicturePDF = new GdPicturePDF();// Load the source document.gdpicturePDF.LoadFromFile(@"C:\temp\source.pdf");// Create an empty string and an empty Boolean to store the validation results.string report = "";PdfValidationConformance conformance = new();// Validate the document.gdpicturePDF.IsValidPDFA(ref report, ref conformance);// Convert the validation report to JSON format.XmlDocument xmlDocument = new();xmlDocument.LoadXml(report);report = JsonConvert.SerializeXmlNode(xmlDocument);// Write the output to the console.string output = $"Verified Conformance:\n{conformance}\nValidation Report:\n{report}";Console.WriteLine(output);// Release unnecessary resources.gdpicturePDF.CloseDocument();
Using gdpicturePDF As GdPicturePDF = New GdPicturePDF() ' Load the source document. gdpicturePDF.LoadFromFile("C:\temp\source.pdf") ' Create an empty string and an empty Boolean to store the validation results. Dim report = "" Dim conformance As PdfValidationConformance = New PdfValidationConformance() ' Validate the document. gdpicturePDF.IsValidPDFA(report, conformance) ' Convert the validation report to JSON format. Dim xmlDocument As XmlDocument = New XmlDocument() xmlDocument.LoadXml(report) report = JsonConvert.SerializeXmlNode(xmlDocument) ' Write the output to the console. Dim output = $"Verified Conformance: {conformance} Validation Report: {report}" Console.WriteLine(output) ' Release unnecessary resources. gdpicturePDF.CloseDocument()End Using
Used methods
Related topics