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 these steps:

  1. Create a GdPicturePDF object.

  2. Load the source document by passing its path to the LoadFromFile method.

  3. Validate the document by calling the IsValidPDFA method.

  4. Write the output to the console.

  5. 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:

  1. Create a GdPicturePDF object.

  2. Load the source document by passing its path to the LoadFromFile method.

  3. Create an empty string and an empty Boolean to store the validation results.

  4. Validate the document by passing the empty string and the empty Boolean as reference parameters to the IsValidPDFA method.

  5. Write the output to the console.

  6. 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 these steps:

  1. Create a GdPicturePDF object.

  2. Load the source document by passing its path to the LoadFromFile method.

  3. Create an empty string and an empty Boolean to store the validation results.

  4. Validate the document by passing the empty string and the empty Boolean as reference parameters to the IsValidPDFA method.

  5. Convert the validation report to JSON format with the XmlDocument class.

  6. Write the output to the console.

  7. 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