> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/get-started/samples/pdfatest.md).

# Convert to PDF/A

Convert PDF to PDF/A format using Apryse Server SDK. All you need is full API enabled in WebViewer to validare pdf/a js. it supports all versions of PDF/A

Sample code for using Apryse Server SDK to programmatically convert generic PDF documents into ISO-compliant, VeraPDF-valid PDF/A files, or to validate PDF/A compliance. Supports all three PDF/A parts (PDF/A-1, PDF/A-2, PDF/A-3), and covers all conformance levels (A, B, U). Code available in Learn more about our [Server SDK](/core/get-started/get-started.md) and [PDF/A Library](/core/pdf-a/pdfa.md). A command-line tool for batch conversion and validation is also available.

{% tabs %}
{% tab title="C#" %}
{% code lineNumbers="true" %}

```csharp
//
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
//

using System;
using pdftron;
using pdftron.SDF;
using pdftron.PDF;
using pdftron.PDF.PDFA;

//-----------------------------------------------------------------------------------
// The sample illustrates how to use PDF/A related API-s.
//-----------------------------------------------------------------------------------
namespace PDFATestCS
{
	class Class1
	{
		private static pdftron.PDFNetLoader pdfNetLoader = pdftron.PDFNetLoader.Instance();
		static Class1() {}
		
		// Relative path to the folder containing test files.
		static string input_path =  "../../../../TestFiles/";
		static string output_path = "../../../../TestFiles/Output/";

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
			PDFNet.Initialize(PDFTronLicense.Key);
			PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms);  // Required for PDFA validation.

			//-----------------------------------------------------------
			// Example 1: PDF/A Validation
			//-----------------------------------------------------------
			try
			{
				string filename = "newsletter.pdf";
				using (PDFACompliance pdf_a = new PDFACompliance(false, input_path+filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
				{
					PrintResults(pdf_a, filename);
				}
			}
			catch (pdftron.Common.PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}

			//-----------------------------------------------------------
			// Example 2: PDF/A Conversion
			//-----------------------------------------------------------
			try
			{
				string filename = "fish.pdf";
				using (PDFACompliance pdf_a = new PDFACompliance(true, input_path+filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
				{
					filename = "pdfa.pdf";
					pdf_a.SaveAs(output_path + filename, false);
				}

				// Re-validate the document after the conversion...
				filename = "pdfa.pdf";
				using (PDFACompliance pdf_a = new PDFACompliance(false, output_path + filename, null, PDFACompliance.Conformance.e_Level2B, null, 10, false))
				{
					PrintResults(pdf_a, filename);				
				}
			}
			catch (pdftron.Common.PDFNetException e)
			{
				Console.WriteLine(e.Message);
			}
			PDFNet.Terminate();
			Console.WriteLine("PDFACompliance test completed.");

		}

		static void PrintResults(PDFACompliance pdf_a, String filename) 
		{
			int err_cnt = pdf_a.GetErrorCount();
			if (err_cnt == 0) 
			{
				Console.WriteLine("{0}: OK.", filename);
			}
			else 
			{
				Console.WriteLine("{0} is NOT a valid PDFA.", filename);
				for (int i=0; i<err_cnt; ++i) 
				{
					PDFACompliance.ErrorCode c = pdf_a.GetError(i);
					Console.WriteLine(" - e_PDFA {0}: {1}.", 
						(int)c, PDFACompliance.GetPDFAErrorMessage(c));

					if (true) 
					{
						int num_refs = pdf_a.GetRefObjCount(c);
						if (num_refs > 0)  
						{
							Console.Write("   Objects: ");
							for (int j=0; j<num_refs; ) 
							{
								Console.Write("{0}", pdf_a.GetRefObj(c, j));
								if (++j!=num_refs) Console.Write(", ");
							}
							Console.WriteLine();
						}
					}
				}
				Console.WriteLine();
			}
		}
	}
}
```

{% endcode %}
{% endtab %}

{% tab title="Go" %}
{% code lineNumbers="true" %}

```go
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2021 by PDFTron Systems Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------

package main
import (
	"fmt"
	"strconv"
    . "pdftron"
)

import  "pdftron/Samples/LicenseKey/GO"

//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//    PDFA standard, using the PDFACompliance class object. 
//---------------------------------------------------------------------------------------

func PrintResults(pdfa PDFACompliance, filename string){
    errCnt := pdfa.GetErrorCount()
    if errCnt == 0{
        fmt.Println(filename + ": OK.")
    }else{
        fmt.Println(filename + " is NOT a valid PDFA.")
        i := int64(0)
        for i < errCnt{
            c := pdfa.GetError(i)
            str1 := " - e_PDFA " + strconv.Itoa(int(c)) + ": " + PDFAComplianceGetPDFAErrorMessage(c) + "."
            if true{
                num_refs := pdfa.GetRefObjCount(c)
                if num_refs > int64(0){
                    str1 = str1 + "\n   Objects: "
                    j := int64(0)
                    for j < num_refs{
                        str1 = str1 + strconv.Itoa(int(pdfa.GetRefObj(c, j)))
                        if j < num_refs-1{
                            str1 = str1 + ", "
						}
                        j = j + 1
					}
				}
			}
            fmt.Println(str1)
            i = i + 1
		}
        fmt.Println("")
	}
}

func main(){
    // Relative path to the folder containing the test files.
    inputPath := "../../TestFiles/"
    outputPath := "../../TestFiles/Output/"
    
    PDFNetInitialize(PDFTronLicense.Key)
    PDFNetSetColorManagement()     // Enable color management (required for PDFA validation).
    
    //-----------------------------------------------------------
    // Example 1: PDF/A Validation
    //-----------------------------------------------------------
    filename := "newsletter.pdf"
	var cErrorCode PdftronPDFPDFAPDFAComplianceErrorCode
    // The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
    // of object numbers that are collected for particular error codes. The default value is 10 
    // in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
    pdfa := NewPDFACompliance(false, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    PrintResults(pdfa, filename)
    pdfa.Destroy()
    
    //-----------------------------------------------------------
    // Example 2: PDF/A Conversion
    //-----------------------------------------------------------
    filename = "fish.pdf"
    pdfa = NewPDFACompliance(true, inputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    filename = "pdfa.pdf"
    pdfa.SaveAs(outputPath + filename, false)
    pdfa.Destroy()
    
    // Re-validate the document after the conversion...
    pdfa = NewPDFACompliance(false, outputPath + filename, "", PDFAComplianceE_Level2B, &cErrorCode, 0, 10)
    PrintResults(pdfa, filename)
    pdfa.Destroy()
	
    PDFNetTerminate()
    fmt.Println("PDFACompliance test completed.")
}
```

{% endcode %}
{% endtab %}

{% tab title="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.*;
import com.pdftron.pdf.pdfa.*;

public class PDFATest {

    // Relative path to the folder containing test files.
    public static final String input_path = "../../TestFiles/";
    public static final String output_path = "../../TestFiles/Output/";

    public static void main(String[] args) {
        try{ 
            PDFNet.initialize(PDFTronLicense.Key());
            PDFNet.setColorManagement(PDFNet.e_lcms); // Required for proper PDF/A validation and conversion.
        
            //-----------------------------------------------------------
            // Example 1: PDF/A Validation
            //-----------------------------------------------------------
        
            String filename = "newsletter.pdf";
            /* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
            of object numbers that are collected for particular error codes. The default value is 10 
            in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
            PDFACompliance pdf_a = new PDFACompliance(false, input_path + filename, null, PDFACompliance.e_Level2B, null, 10);
            printResults(pdf_a, filename);
            pdf_a.destroy();
        } catch (PDFNetException e) {
            System.out.println(e.getMessage());
        }
        
        
        
            //-----------------------------------------------------------
            // Example 2: PDF/A Conversion
            //-----------------------------------------------------------
        try {
            String filename = "fish.pdf";
            PDFACompliance pdf_a = new PDFACompliance(true, input_path + filename, null, PDFACompliance.e_Level2B, null, 10);
            filename = "pdfa.pdf";
            pdf_a.saveAs(output_path + filename, false);
            pdf_a.destroy();
            // output "pdf_a.pdf"

            // Re-validate the document after the conversion...
            pdf_a = new PDFACompliance(false, output_path + filename, null, PDFACompliance.e_Level2B, null, 10);
            printResults(pdf_a, filename);
            pdf_a.destroy();

            PDFNet.terminate();
        } catch (PDFNetException e) {
            System.out.println(e.getMessage());
        }

        System.out.println("PDFACompliance test completed.");
    }

    static void printResults(PDFACompliance pdf_a, String filename) {
        try {
            int err_cnt = pdf_a.getErrorCount();
            System.out.print(filename);
            if (err_cnt == 0) {
                System.out.print(": OK.\n");
            } else {
                System.out.println(" is NOT a valid PDFA.");
                for (int i = 0; i < err_cnt; ++i) {
                    int c = pdf_a.getError(i);
                    System.out.println(" - e_PDFA " + c + ": " + PDFACompliance.getPDFAErrorMessage(c) + ".");
                    if (true) {
                        int num_refs = pdf_a.getRefObjCount(c);
                        if (num_refs > 0) {
                            System.out.print("   Objects: ");
                            for (int j = 0; j < num_refs; ) {
                                System.out.print(String.valueOf(pdf_a.getRefObj(c, j)));
                                if (++j != num_refs) System.out.print(", ");
                            }
                            System.out.println();
                        }
                    }
                }
                System.out.println();
            }
        } catch (PDFNetException e) {
            System.out.println(e.getMessage());
        }
    }

}
```

{% endcode %}
{% endtab %}

{% tab title="C++" %}
{% code lineNumbers="true" %}

```cpp
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

#include <PDF/PDFNet.h>
//#include <PDF/PDFDoc.h>
#include <PDF/PDFA/PDFACompliance.h>
#include <string>
#include <iostream>
#include "../../LicenseKey/CPP/LicenseKey.h"

using namespace std;
using namespace pdftron;
using namespace pdftron::PDF;
using namespace pdftron::PDF::PDFA;

void PrintResults(PDFACompliance& pdf_a, UString filename) 
{
	int err_cnt = static_cast<int>(pdf_a.GetErrorCount());
	if (err_cnt == 0) 
	{
		cout << filename << ": OK.\n";
	}
	else 
	{
		cout << filename << " is NOT a valid PDFA.\n";
		for (int i=0; i<err_cnt; ++i) 
		{
			PDFACompliance::ErrorCode c = pdf_a.GetError(i);
			cout << " - e_PDFA " << c << ": " << PDFACompliance::GetPDFAErrorMessage(c) << ".\n";
			if (true) 
			{
				int num_refs = static_cast<int>(pdf_a.GetRefObjCount(c));
				if (num_refs > 0)  
				{
					cout << "   Objects: ";
					for (int j=0; j<num_refs; ++j) 
					{
						cout << pdf_a.GetRefObj(c, j);
						if (j<num_refs-1) 
							cout << ", ";
					}
					cout << endl;
				}
			}
		}
		cout << endl;
	}
}



//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//	PDFA standard, using the PDFACompliance class object. 
//---------------------------------------------------------------------------------------
int main(int argc, char *argv[])
{	
	int ret = 0;
	UString input_path("../../TestFiles/");
	UString output_path("../../TestFiles/Output/");
	PDFNet::Initialize(LicenseKey);
	PDFNet::SetColorManagement();  // Enable color management (required for PDFA validation).

	//-----------------------------------------------------------
	// Example 1: PDF/A Validation
	//-----------------------------------------------------------
	try
	{
		UString filename("newsletter.pdf");
		/* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
		of object numbers that are collected for particular error codes. The default value is 10 
		in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
		PDFACompliance pdf_a(false, input_path+filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
		PrintResults(pdf_a, filename);
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...) {
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	//-----------------------------------------------------------
	// Example 2: PDF/A Conversion
	//-----------------------------------------------------------
	try
	{
		UString filename("fish.pdf");
		PDFACompliance pdf_a(true, input_path+filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
		filename = "pdfa.pdf";
		pdf_a.SaveAs(output_path + filename);

		// Re-validate the document after the conversion...
		PDFACompliance comp(false, output_path + filename, 0, PDFACompliance::e_Level2B, 0, 0, 10);
		PrintResults(comp, filename);				
	}
	catch (Common::Exception& e)
	{
		cout << e << endl;
		ret = 1;
	}
	catch (...) {
		cout << "Unknown Exception" << endl;
		ret = 1;
	}

	cout << "PDFACompliance test completed." << endl;
	PDFNet::Terminate();
	return ret;
}
```

{% endcode %}
{% endtab %}

{% tab title="JavaScript" %}
{% code lineNumbers="true" %}

```js
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

const { PDFNet } = require('@pdftron/pdfnet-node');
const PDFTronLicense = require('../LicenseKey/LicenseKey');

((exports) => {

  exports.runPDFA = () => {

    const printResults = async (pdfa, filename) => {

      const errorCount = await pdfa.getErrorCount();
      if (errorCount === 0) {
        console.log(filename + ': OK.');
      } else {
        console.log(filename + ' is NOT a valid PDFA.');
        for (let i = 0; i < errorCount; i++) {
          const errorCode = await pdfa.getError(i);
          const errorMsg = await PDFNet.PDFACompliance.getPDFAErrorMessage(errorCode);
          console.log(' - e_PDFA ' + errorCode + ': ' + errorMsg + '.');
          const numRefs = await pdfa.getRefObjCount(errorCode);
          if (numRefs > 0) {
            const objs = [];
            for (let j = 0; j < numRefs; j++) {
              const objRef = await pdfa.getRefObj(errorCode, j);
              objs.push(objRef);
            }
            console.log('   Objects: ' + objs.join(', '));
          }
        }
        console.log('');
      }
    }

    //---------------------------------------------------------------------------------------
    // The following sample illustrates how to parse and check if a PDF document meets the
    //	PDFA standard, using the PDFACompliance class object. 
    //---------------------------------------------------------------------------------------
    const main = async () => {
      const inputPath = '../TestFiles/';
      const outputPath = inputPath + 'Output/';
      await PDFNet.setColorManagement();  // Enable color management (required for PDFA validation).

      //-----------------------------------------------------------
      // Example 1: PDF/A Validation
      //-----------------------------------------------------------
      try {
        const filename = 'newsletter.pdf';
        /* The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
        of object numbers that are collected for particular error codes. The default value is 10 
        in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs. */
        const pdfa = await PDFNet.PDFACompliance.createFromFile(false, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
        await printResults(pdfa, filename);
      } catch (err) {
        console.log(err);
      }

      //-----------------------------------------------------------
      // Example 2: PDF/A Conversion
      //-----------------------------------------------------------
      try {
        let filename = 'fish.pdf';
        const pdfa = await PDFNet.PDFACompliance.createFromFile(true, inputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
        filename = 'pdfa.pdf';
        await pdfa.saveAsFromFileName(outputPath + filename);

        // Re-validate the document after the conversion...
        const comp = await PDFNet.PDFACompliance.createFromFile(false, outputPath + filename, '', PDFNet.PDFACompliance.Conformance.e_Level2B);
        await printResults(comp, filename);
      } catch (err) {
        console.log(err);
      }

      console.log('PDFACompliance test completed.')
    };

    PDFNet.runWithCleanup(main, PDFTronLicense.Key).catch(function (error) { console.log('Error: ' + JSON.stringify(error)); }).then(function () { return PDFNet.shutdown(); });
  };
  exports.runPDFA();
})(exports);
// eslint-disable-next-line spaced-comment
//# sourceURL=PDFATest.js
```

{% endcode %}
{% endtab %}

{% tab title="PHP" %}
{% code lineNumbers="true" %}

```php
<?php
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult LICENSE.txt regarding license information.
//---------------------------------------------------------------------------------------
if(file_exists("../../../PDFNetC/Lib/PDFNetPHP.php"))
include("../../../PDFNetC/Lib/PDFNetPHP.php");
include("../../LicenseKey/PHP/LicenseKey.php");

//---------------------------------------------------------------------------------------
// The following sample illustrates how to parse and check if a PDF document meets the
//	PDFA standard, using the PDFACompliance class object. 
//---------------------------------------------------------------------------------------


function PrintResults($pdf_a, $filename) 
{
	$err_cnt = $pdf_a->GetErrorCount();
	if ($err_cnt == 0) 
	{
		echo nl2br($filename.": OK.\n");
	}
	else 
	{
		echo nl2br($filename." is NOT a valid PDFA.\n");
		for ($i=0; $i<$err_cnt; ++$i) 
		{
			$c = $pdf_a->GetError($i);
			$str1 = " - e_PDFA ".$c.": ".PDFACompliance::GetPDFAErrorMessage($c).".";
			if (true) 
			{
				$num_refs = $pdf_a->GetRefObjCount($c);
				if ($num_refs > 0)  
				{
					$str1 = $str1."\n   Objects: ";
					for ($j=0; $j<$num_refs; ++$j) 
					{
						$str1 = $str1.$pdf_a->GetRefObj($c, $j);
						if ($j<$num_refs-1) 
							$str1 = $str1. ", ";
					}
				}
			}
			echo nl2br($str1."\n");
		}
		echo nl2br("\n");
	}
}

	// Relative path to the folder containing the test files.
	$input_path = getcwd()."/../../TestFiles/";
	$output_path = getcwd()."/../../TestFiles/Output/";

	PDFNet::Initialize($LicenseKey);
	PDFNet::GetSystemFontList();    // Wait for fonts to be loaded if they haven't already. This is done because PHP can run into errors when shutting down if font loading is still in progress.
	PDFNet::SetColorManagement();  // Enable color management (required for PDFA validation).

	//-----------------------------------------------------------
	// Example 1: PDF/A Validation
	//-----------------------------------------------------------
	$filename = "newsletter.pdf";
	// The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
	// of object numbers that are collected for particular error codes. The default value is 10 
	// in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
	$pdf_a = new PDFACompliance(false, $input_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);
	PrintResults($pdf_a, $filename);
	$pdf_a->Destroy();

	//-----------------------------------------------------------
	// Example 2: PDF/A Conversion
	//-----------------------------------------------------------
	$filename = "fish.pdf";
	
	$pdf_a = new PDFACompliance(true, $input_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);
	$filename = "pdfa.pdf";
	$pdf_a->SaveAs($output_path.$filename, false);
	$pdf_a->Destroy();

	// Re-validate the document after the conversion...
	$pdf_a = new PDFACompliance(false, $output_path.$filename, "", PDFACompliance::e_Level2B, 0, 0, 10);		
	PrintResults($pdf_a, $filename);
	$pdf_a->Destroy();
	PDFNet::Terminate();	
	echo nl2br("PDFACompliance test completed.\n");
?>
```

{% endcode %}
{% endtab %}

{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

import site
site.addsitedir("../../../PDFNetC/Lib")
import sys
from PDFNetPython import *

sys.path.append("../../LicenseKey/PYTHON")
from LicenseKey import *

#---------------------------------------------------------------------------------------
# The following sample illustrates how to parse and check if a PDF document meets the
#    PDFA standard, using the PDFACompliance class object. 
#---------------------------------------------------------------------------------------

def PrintResults(pdf_a, filename):
    err_cnt = pdf_a.GetErrorCount()
    if err_cnt == 0:
        print(filename + ": OK.")
    else:
        print(filename + " is NOT a valid PDFA.")
        i = 0
        while i < err_cnt:
            c = pdf_a.GetError(i)
            str1 = " - e_PDFA " + str(c) + ": " + PDFACompliance.GetPDFAErrorMessage(c) + "."
            if True:
                num_refs = pdf_a.GetRefObjCount(c)
                if num_refs > 0:
                    str1 = str1 + "\n   Objects: "
                    j = 0
                    while j < num_refs:
                        str1 = str1 + str(pdf_a.GetRefObj(c, j))
                        if j < num_refs-1:
                            str1 = str1 + ", "
                        j = j + 1
            print(str1)
            i = i + 1
        print('')	

def main():
    # Relative path to the folder containing the test files.
    input_path = "../../TestFiles/"
    output_path = "../../TestFiles/Output/"
    
    PDFNet.Initialize(LicenseKey)
    PDFNet.SetColorManagement()     # Enable color management (required for PDFA validation).
    
    #-----------------------------------------------------------
    # Example 1: PDF/A Validation
    #-----------------------------------------------------------
    filename = "newsletter.pdf"
    # The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
    # of object numbers that are collected for particular error codes. The default value is 10 
    # in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
    pdf_a = PDFACompliance(False, input_path+filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
    PrintResults(pdf_a, filename)
    pdf_a.Destroy()
    
    #-----------------------------------------------------------
    # Example 2: PDF/A Conversion
    #-----------------------------------------------------------
    filename = "fish.pdf"
    pdf_a = PDFACompliance(True, input_path + filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
    filename = "pdfa.pdf"
    pdf_a.SaveAs(output_path + filename, False)
    pdf_a.Destroy()
    
    # Re-validate the document after the conversion...
    pdf_a = PDFACompliance(False, output_path + filename, None, PDFACompliance.e_Level2B, 0, 0, 10)
    PrintResults(pdf_a, filename)
    pdf_a.Destroy()
	
    PDFNet.Terminate()
    print("PDFACompliance test completed.")

if __name__ == '__main__':
    main()
```

{% endcode %}
{% endtab %}

{% tab title="Ruby" %}
{% code lineNumbers="true" %}

```ruby
#---------------------------------------------------------------------------------------
# Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
# Consult LICENSE.txt regarding license information.
#---------------------------------------------------------------------------------------

require '../../../PDFNetC/Lib/PDFNetRuby'
include PDFNetRuby
require '../../LicenseKey/RUBY/LicenseKey'

$stdout.sync = true

#---------------------------------------------------------------------------------------
# The following sample illustrates how to parse and check if a PDF document meets the
# PDFA standard, using the PDFACompliance class object. 
#---------------------------------------------------------------------------------------

# Relative path to the folder containing the test files.
input_path = "../../TestFiles/"
output_path = "../../TestFiles/Output/"

def PrintResults(pdf_a, filename)
	err_cnt = pdf_a.GetErrorCount
	if err_cnt == 0
		puts filename + ": OK."
	else
		puts filename + " is NOT a valid PDFA."	
		i = 0
		while i < err_cnt do
			c = pdf_a.GetError(i)
			str1 = " - e_PDFA " + c.to_s + ": " + PDFACompliance.GetPDFAErrorMessage(c) + "."
			if true
				num_refs = pdf_a.GetRefObjCount(c)
				if num_refs > 0
					str1 = str1 + "\n   Objects: "
					j = 0
					while j < num_refs do
						str1 = str1 + pdf_a.GetRefObj(c, j).to_s
						if j < num_refs-1
							str1 = str1 + ", "
						end
						j = j + 1
					end
				end
			end
			puts str1
			i = i + 1
		end
		puts "\n"
	end
end
	
	PDFNet.Initialize(PDFTronLicense.Key)
	PDFNet.SetColorManagement	 # Enable color management (required for PDFA validation).
	
	#-----------------------------------------------------------
	# Example 1: PDF/A Validation
	#-----------------------------------------------------------
	filename = "newsletter.pdf"
	# The max_ref_objs parameter to the PDFACompliance constructor controls the maximum number 
	# of object numbers that are collected for particular error codes. The default value is 10 
	# in order to prevent spam. If you need all the object numbers, pass 0 for max_ref_objs.
	pdf_a = PDFACompliance.new(false, input_path+filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
	PrintResults(pdf_a, filename)
	pdf_a.Destroy
	
	#-----------------------------------------------------------
	# Example 2: PDF/A Conversion
	#-----------------------------------------------------------
	filename = "fish.pdf"
	pdf_a = PDFACompliance.new(true, input_path + filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
	filename = "pdfa.pdf"
	pdf_a.SaveAs(output_path + filename, false)
	pdf_a.Destroy
	
	# Re-validate the document after the conversion...
	pdf_a = PDFACompliance.new(false, output_path + filename, nil, PDFACompliance::E_Level2B, 0, 0, 10)
	PrintResults(pdf_a, filename)
	pdf_a.Destroy
	PDFNet.Terminate
	puts "PDFACompliance test completed."
```

{% endcode %}
{% endtab %}

{% tab title="VB" %}
{% code lineNumbers="true" %}

```vb
'---------------------------------------------------------------------------------------
' Copyright (c) 2001-2024 by Apryse Software Inc. All Rights Reserved.
' Consult legal.txt regarding legal and license information.     
'---------------------------------------------------------------------------------------
Imports System

Imports PDFTRON
Imports PDFTRON.PDF
Imports PDFTRON.PDF.PDFA

'-----------------------------------------------------------------------------------
' The sample illustrates how to use PDF/A related API-s.
'-----------------------------------------------------------------------------------

Module mainModule
    Dim pdfNetLoader As PDFNetLoader
    Sub New()
        pdfNetLoader = pdftron.PDFNetLoader.Instance()
    End Sub

    ' The main entry point for the application.
    Sub Main()

        PDFNet.Initialize(PDFTronLicense.Key)
        PDFNet.SetColorManagement(PDFNet.CMSType.e_lcms) 'Required for PDFA validation.

        'Relative path to the folder containing test files.
        Dim input_path As String = "../../../../TestFiles/"
        Dim filename As String = "newsletter.pdf"
        Dim output_path As String = "../../../../TestFiles/Output/"


        '//-----------------------------------------------------------
        '// Example 1: PDF/A Validation
        '//-----------------------------------------------------------
        Try
            filename = "newsletter.pdf"
            Dim pdf_a As PDFACompliance = New PDFACompliance(False, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
            PrintResults(pdf_a, filename)
            pdf_a.Dispose()
        Catch e As PDFTRON.Common.PDFNetException
            Console.WriteLine(e.Message)
        End Try

        '//-----------------------------------------------------------
        '// Example 2: PDF/A Conversion
        '//-----------------------------------------------------------
        Try
            filename = "fish.pdf"
            Using pdf_a As PDFACompliance = New PDFACompliance(True, input_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
                filename = "pdfa.pdf"
                pdf_a.SaveAs(output_path + filename, False)
            End Using

            '// Re-validate the document after the conversion...
            filename = "pdfa.pdf"
            Using pdf_a As PDFACompliance = New PDFACompliance(False, output_path + filename, Nothing, PDFACompliance.Conformance.e_Level2B, Nothing, 10, False)
                PrintResults(pdf_a, filename)
            End Using
        Catch e As pdftron.Common.PDFNetException
            Console.WriteLine(e.Message)
        End Try
        PDFNet.Terminate()
        Console.WriteLine("PDFACompliance test completed.")
    End Sub

    Function PrintResults(ByRef pdf_a As PDFACompliance, ByVal filename As String) As Int32
        PrintResults = 0
        Dim err_cnt As Int32 = pdf_a.GetErrorCount()
        If err_cnt = 0 Then
            Console.WriteLine("{0}: OK.", filename)
        Else
            Dim i As Int32
            Console.WriteLine("{0} is NOT a valid PDFA.", filename)
            For i = 0 To err_cnt - 1 Step 1
                Dim c As PDFACompliance.ErrorCode = pdf_a.GetError(i)
                Console.WriteLine(" - e_PDFA {0}: {1}.", Int(c), PDFACompliance.GetPDFAErrorMessage(c))
                If True Then
                    Dim num_refs As Int32 = pdf_a.GetRefObjCount(c)
                    If num_refs > 0 Then
                        Console.Write("   Objects: ")
                        Dim j As Int32
                        For j = 0 To num_refs - 1 Step 1
                            Console.Write("{0}", pdf_a.GetRefObj(c, j))
                            If Not (j + 1) = num_refs Then
                                Console.Write(", ")
                            End If
                        Next j
                        Console.WriteLine()
                    End If
                End If
            Next i
            Console.WriteLine()
        End If
    End Function

End Module
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/core/get-started/samples/pdfatest.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
