> 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/android/get-started/samples/pdfatest.md).

# PDF/A

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

Sample Java code for using Apryse 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). Learn more about our [Android SDK](/core/get-started/languages/java.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="Java" %}
{% code lineNumbers="true" %}

```java
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

package com.pdftron.android.pdfnetsdksamples.samples;

import com.pdftron.android.pdfnetsdksamples.OutputListener;
import com.pdftron.android.pdfnetsdksamples.PDFNetSample;
import com.pdftron.android.pdfnetsdksamples.R;
import com.pdftron.android.pdfnetsdksamples.util.Utils;
import com.pdftron.common.PDFNetException;
import com.pdftron.pdf.PDFNet;
import com.pdftron.pdf.pdfa.PDFACompliance;

import java.util.ArrayList;

public class PDFATest extends PDFNetSample {

	private static OutputListener mOutputListener;

	private static ArrayList<String> mFileList = new ArrayList<>();

    public PDFATest() {
        setTitle(R.string.sample_pdfa_title);
        setDescription(R.string.sample_pdfa_description);

        // The standard library does not include PDF/A validation/conversion,
        // thus this sample will fail. Please, comment out this call
        // if using the full libraries.
        // DisableRun();
    }

	@Override
	public void run(OutputListener outputListener) {
		super.run(outputListener);
		mOutputListener = outputListener;
		mFileList.clear();
		printHeader(outputListener);
        try{ 
            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, Utils.getAssetTempFile(INPUT_PATH + filename).getAbsolutePath(), 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, Utils.getAssetTempFile(INPUT_PATH + filename).getAbsolutePath(), null, PDFACompliance.e_Level2B, null, 10);
            filename = "pdfa.pdf";
            pdf_a.saveAs(Utils.createExternalFile(filename, mFileList).getAbsolutePath(), false);
            pdf_a.destroy();
            // output "pdf_a.pdf"

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

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

        mOutputListener.println("PDFACompliance test completed.");

		for (String file : mFileList) {
			addToFileList(file);
		}
		printFooter(outputListener);
	}


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

}
```

{% endcode %}
{% endtab %}

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

```kotlin
//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2019 by PDFTron Systems Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------

package com.pdftron.android.pdfnetsdksamples.samples

import com.pdftron.android.pdfnetsdksamples.OutputListener
import com.pdftron.android.pdfnetsdksamples.PDFNetSample
import com.pdftron.android.pdfnetsdksamples.R
import com.pdftron.android.pdfnetsdksamples.util.Utils
import com.pdftron.common.PDFNetException
import com.pdftron.pdf.PDFNet
import com.pdftron.pdf.pdfa.PDFACompliance

import java.util.ArrayList

class PDFATest : PDFNetSample() {
    init {
        setTitle(R.string.sample_pdfa_title)
        setDescription(R.string.sample_pdfa_description)

        // The standard library does not include PDF/A validation/conversion,
        // thus this sample will fail. Please, comment out this call
        // if using the full libraries.
        // DisableRun();
    }

    override fun run(outputListener: OutputListener?) {
        super.run(outputListener)
        mOutputListener = outputListener
        mFileList.clear()
        printHeader(outputListener!!)
        try {
            PDFNet.setColorManagement(PDFNet.e_lcms) // Required for proper PDF/A validation and conversion.

            //-----------------------------------------------------------
            // Example 1: PDF/A Validation
            //-----------------------------------------------------------

            val 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. */
            val pdf_a = PDFACompliance(false, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + filename)!!.absolutePath, null, PDFACompliance.e_Level2B, null, 10)
            printResults(pdf_a, filename)
            pdf_a.destroy()
        } catch (e: PDFNetException) {
            println(e.message)
        }

        //-----------------------------------------------------------
        // Example 2: PDF/A Conversion
        //-----------------------------------------------------------
        try {
            var filename = "fish.pdf"
            var pdf_a = PDFACompliance(true, Utils.getAssetTempFile(PDFNetSample.INPUT_PATH + filename)!!.absolutePath, null, PDFACompliance.e_Level2B, null, 10)
            filename = "pdfa.pdf"
            pdf_a.saveAs(Utils.createExternalFile(filename, mFileList).absolutePath, false)
            pdf_a.destroy()

            // Re-validate the document after the conversion...
            pdf_a = PDFACompliance(false, Utils.createExternalFile(filename, mFileList).absolutePath, null, PDFACompliance.e_Level2B, null, 10)
            printResults(pdf_a, filename)
            pdf_a.destroy()

        } catch (e: PDFNetException) {
            println(e.message)
        }

        mOutputListener!!.println("PDFACompliance test completed.")

        for (file in mFileList) {
            addToFileList(file)
        }
        printFooter(outputListener)
    }

    companion object {

        private var mOutputListener: OutputListener? = null

        private val mFileList = ArrayList<String>()

        internal fun printResults(pdf_a: PDFACompliance, filename: String) {
            try {
                val err_cnt = pdf_a.errorCount
                mOutputListener!!.print(filename)
                if (err_cnt == 0) {
                    mOutputListener!!.print(": OK.\n")
                } else {
                    mOutputListener!!.println(" is NOT a valid PDFA.")
                    for (i in 0 until err_cnt) {
                        val c = pdf_a.getError(i)
                        mOutputListener!!.println(" - e_PDFA " + c + ": " + PDFACompliance.getPDFAErrorMessage(c) + ".")
                        if (true) {
                            val num_refs = pdf_a.getRefObjCount(c)
                            if (num_refs > 0) {
                                mOutputListener!!.print("   Objects: ")
                                var j = 0
                                while (j < num_refs) {
                                    mOutputListener!!.print(pdf_a.getRefObj(c, j).toString())
                                    if (++j != num_refs) mOutputListener!!.print(", ")
                                }
                                mOutputListener!!.println()
                            }
                        }
                    }
                    mOutputListener!!.println()
                }
            } catch (e: PDFNetException) {
                println(e.message)
            }

        }
    }

}
```

{% 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/android/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.
