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

# PDF/A - Validate and Convert

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

{% hint style="info" %}
**Requirements**

*These packages are required to use these features in production. Trial keys have unlimited access to all features*

<a href="/web/get-started/readme.md" class="button primary">Web SDK</a><a href="https://apryse.com/capabilities#Archive" class="button primary">Package: Archive</a><a href="/web/full-api/full-api-overview.md" class="button primary">Full API</a><a href="https://showcase.apryse.com/pdfa-conversion" class="button primary">Live demo</a>
{% endhint %}

Sample JavaScript 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).

This sample is utilizing the option to [run code programmatically, without the Viewer.](/web/get-started/without-viewer.md) For other WebViewer implementation options, check out:

* [Validate PDF/A - Showcase Demo](https://docs.apryse.com/web/samples/showcase-demo-validate-pdfa)
* [PDF/A Conversion - Showcase Demo](https://docs.apryse.com/web/samples/showcase-demo-pdfa-conversion)

Or check out the [c](/cli/pdf-a-manager/pdfa-manager.md)[ommand-line tool for batch conversion and validation.](/cli/pdf-a-manager/pdfa-manager.md)

### **Implementation steps**

To convert or validate PDF/A programmatically with Web SDK:

Step 1: Follow [get started in your preferred web stack for WebViewer](/web/get-started/readme.md) Step 2: Follow set up to [implement Full API code without viewer](/web/full-api/running-without-viewer.md) Step 3: Add the sample code provided in this guide

This full sample is included in the [manual download of WebViewer.](/web/get-started/manually.md#1-download-webviewer)

<pre class="language-js" data-line-numbers><code class="lang-js">//---------------------------------------------------------------------------------------
// Copyright (c) 2001-2023 by Apryse Software Inc. All Rights Reserved.
// Consult legal.txt regarding legal and license information.
//---------------------------------------------------------------------------------------
(exports => {
  exports.runPDFA = () => {
    const PDFNet = exports.Core.PDFNet;

    const main = async () => {
      try {
        console.log('PDFA validation test begins.');

        const inputURL = '../TestFiles/';
        const inputFilename = 'newsletter.pdf';

        const convert = false;
        const pwd = '';
        let exceptions;
        const maxRefObjs = 10;
        const firstStop = false;
        const url = inputURL + inputFilename;

        const pdfa = await PDFNet.PDFACompliance.createFromUrl(convert, url, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs, firstStop);

        const errorCount = await pdfa.getErrorCount();
        if (errorCount === 0) {
          console.log(inputFilename + ' is a valid PDFA.');
        } else {
          console.log(inputFilename + ' is NOT a valid PDFA.');
          for (let i = 0; i &#x3C; errorCount; i++) {
            const errorCode = await pdfa.getError(i);
            const errorMsg = await PDFNet.PDFACompliance.getPDFAErrorMessage(errorCode);
            const numRefs = await pdfa.getRefObjCount(errorCode);
            if (numRefs > 0) {
              const objs = [];
              for (let j = 0; j &#x3C; numRefs; j++) {
                const objRef = await pdfa.getRefObj(errorCode, j);
                objs.push(objRef);
              }
              console.log('Error:' + errorMsg + '. Objects:' + objs.toString());
            }
          }
        }
      } catch (err) {
        console.log(err);
      }
      try {
        console.log('PDFA conversion test begins.');

        const inputURL = '../TestFiles/';
        const inputFilename = 'fish.pdf';
        const outputFilename = 'fish_pdfa.pdf';

        const convert = true;
        const pwd = '';
        let exceptions;
        const maxRefObjs = 10;
        const urlInput = inputURL + inputFilename;

        console.log('Converting input document: ' + inputFilename);
        const pdfa = await PDFNet.PDFACompliance.createFromUrl(convert, urlInput, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs);

        const errorCount = await pdfa.getErrorCount();
        if (errorCount === 0) {
          console.log(inputFilename + ' is a valid PDFA.');
        } else {
          console.log(inputFilename + ' is NOT a valid PDFA.');
        }

        console.log('Save and validate the converted document: ' + outputFilename);
        const linearize = true;
        const docBuffer = await pdfa.saveAsFromBuffer(linearize);
        saveBufferAsPDFDoc(docBuffer, outputFilename);
        const validateOnly = false;
        const pdfaValidate = await PDFNet.PDFACompliance.createFromBuffer(validateOnly, docBuffer, pwd, PDFNet.PDFACompliance.Conformance.e_Level1B, exceptions, maxRefObjs);
        const errorCountValidate = await pdfaValidate.getErrorCount();
        if (errorCountValidate === 0) {
          console.log(outputFilename + ' is a valid PDFA.');
        } else {
          console.log(outputFilename + ' is NOT a valid PDFA.');
        }
      } catch (err) {
        console.log(err);
      }
    };

    // add your own license key as the second parameter, e.g. PDFNet.runWithCleanup(main, '<code class="expression">visitor.claims.wvKey || "YOUR_LICENSE_KEY"</code>')
    PDFNet.runWithCleanup(main);
  };
})(window);
// eslint-disable-next-line spaced-comment
//# sourceURL=PDFATest.js
</code></pre>


---

# 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/web/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.
