> 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/showcase-demo-pdfa-conversion.md).

# PDF/A Conversion - Showcase Demo

Generate PDF/A compliant documents from PDFs.

{% 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="https://showcase.apryse.com/pdfa-conversion" class="button primary">Live demo</a>
{% endhint %}

Easily generate [PDF/A compliant](https://en.wikipedia.org/wiki/PDF/A) documents from PDFs in your browser or application.

This code sample follows the [Apryse Showcase: PDF/A Conversion Demo](https://showcase.apryse.com/pdfa-conversion), and allows you to:

* Add annotations
* Edit the layout and content
* Convert PDF to various PDF/A formats (such as 1,2,3, or 4)
* Download the converted PDF/A

### **Implementation steps**

To convert to PDF/A with WebViewer:

Step 1: Follow [get started in your preferred web stack for WebViewer](/web/get-started/readme.md) Step 2: Add the ES6 JavaScript sample code provided in this guide

Once you generate your license key, it will automatically be included in your sample code below.

{% @apryse-license-key/apryse-license-key platform="WEB\_VIEWER" variant="compact" %}

<pre class="language-js" data-line-numbers><code class="lang-js">// ES6 Compliant Syntax
// GitHub Copilot v1.0 - Model: Claude-3.5 Sonnet - July 9, 2025
// File: examples/pdfa-conversion/index.js
import WebViewer from '@pdftron/webviewer';

const licenseKey = '<code class="expression">visitor.claims.wvKey || "YOUR_WEBVIEWER_LICENSE_KEY"</code>';

const element = document.getElementById('viewer');
let instCore = null;
const onLoad = async (instance) => {
  instCore = instance.Core;
};

WebViewer(
  {
    path: '/lib',
    licenseKey: licenseKey, 
    initialDoc: 'https://apryse.s3.amazonaws.com/public/files/samples/WebviewerDemoDoc.pdf',
    fullAPI: true,
  },
  element
).then((instance) => {
  onLoad(instance);
});

let pdfaBlob = null;

const buttonConvert = document.createElement('button');
buttonConvert.textContent = 'PDF/A convert';
buttonConvert.onclick = async () => {
  const doc = instCore.documentViewer.getDocument();
  const xfdfString = await instCore.annotationManager.exportAnnotations();
  const data = await doc.getFileData({
    xfdfString,
  });

  const conformanceLevel = instCore.PDFNet.PDFACompliance.Conformance[`${levelSelect.value}`];
  const PDFNetFile = await instCore.PDFNet.PDFACompliance.createFromBuffer(
    true,
    data,
    '',
    conformanceLevel
  );
  const buf = await PDFNetFile.saveAsFromBuffer(false);
  pdfaBlob = new Blob([buf], { type: 'application/pdf' });

  console.log("PDF/A conversion successful.");
};

// UI section
//
// Helper code to add controls to the viewer holding the buttons and dropdown
// This code creates a container for the buttons and dropdown, styles them, and adds them to the viewer
// 


const buttonDownload = document.createElement('button');
buttonDownload.textContent = 'Download PDF/A';
buttonDownload.onclick = () => {
  if (pdfaBlob) {
    const url = URL.createObjectURL(pdfaBlob);
    const link = document.createElement('a');
    link.href = url;
    link.download = 'converted.pdf';
    link.click();
  } else {
    alert('PDF/A not available to download.\nPlease convert the document to PDF/A first.');
  }
};

// Create a dropdown for PDF/A levels
// This dropdown allows users to select the PDF/A compliance level they want to convert to.
// The options correspond to the different PDF/A levels supported by PDFNet.

const levelSelect = document.createElement('select');
const levels = [
  { value: 'e_Level1A', label: 'PDF/A-1a' },
  { value: 'e_Level1B', label: 'PDF/A-1b' },
  { value: 'e_Level2A', label: 'PDF/A-2a' },
  { value: 'e_Level2B', label: 'PDF/A-2b' },
  { value: 'e_Level2U', label: 'PDF/A-2u' },
  { value: 'e_Level3A', label: 'PDF/A-3a' },
  { value: 'e_Level3B', label: 'PDF/A-3b' },
  { value: 'e_Level3U', label: 'PDF/A-3u' },
  { value: 'e_Level4', label: 'PDF/A-4' },
  { value: 'e_Level4E', label: 'PDF/A-4e' },
  { value: 'e_Level4F', label: 'PDF/A-4f' },
];

// Populate the dropdown with options
levels.forEach(level => {
  const option = document.createElement('option');
  option.value = level.value;
  option.textContent = level.label;
  levelSelect.appendChild(option);
});

// set default value for the dropdown
levelSelect.value = levels[3].value; // Default to PDF/A-2b
levelSelect.oninput = () => {
  console.log(`Selected PDF/A level: ${levelSelect.value}`);
  pdfaBlob = null; // Reset the blob when the level changes
};

const levelLabel = document.createElement('label');
levelLabel.textContent = 'Select PDF/A level: ';

// Create a container for all controls (label, dropdown, and buttons)
const controlsContainer = document.createElement('div');

levelLabel.className = 'level-label';
buttonDownload.className = 'btn-download';
buttonConvert.className = 'btn-convert';
levelSelect.className = 'level-select';
controlsContainer.className = 'button-container';

controlsContainer.appendChild(levelLabel);
controlsContainer.appendChild(levelSelect);
controlsContainer.appendChild(buttonConvert);
controlsContainer.appendChild(buttonDownload);
element.insertBefore(controlsContainer, element.firstChild);
</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/showcase-demo-pdfa-conversion.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.
