Convert PDFs and Images to PDF/A Using JavaScript
PSPDFKit for Web enables you to convert PDFs, Office documents, and images to PDF/A client-side, without the need for server-side processing. For more information on the supported source file formats, see the list of supported file types.
PSPDFKit for Web supports converting source files into all PDF/A versions and conformance levels:
-
PDF/A-1a, PDF/A-1b
-
PDF/A-2a, PDF/A-2u, PDF/A-2b
-
PDF/A-3a, PDF/A-3u, PDF/A-3b
-
PDF/A-4, PDF/A-4e, PDF/A-4f
For more information on the long-term preservation of documents, check out our demo video below, or have a look at our complete guide to PDF/A.
Converting Documents to PDF/A
To convert a PDF, an Office file, or an image to PDF/A, follow these steps:
-
Use the
exportPDF
method to convert the source file to PDF/A. This method takes an object as its parameter, which configures the conversion. For conversion to PDF/A, add anoutputFormat
key to the configuration object that you pass to theexportPDF
method. The value of this key is an object. Within this object, the value of theconformance
key is a member of theConformance
enumeration that specifies the conformance level of the output PDF document. If you set this value totrue
, the output is a document with conformance level PDF/A-2b. -
Save the output document. The
exportPDF
method returns aPromise
that resolves to anArrayBuffer
that contains the output PDF/A document. You can use the resultingArrayBuffer
to download or persist the output PDF/A in storage. For more information on downloading or persisting the exportedArrayBuffer
, see the guides on saving a document.
The example below loads a PDF document and exports it to a PDF with conformance level PDF/A-4f:
PSPDFKit.load({ container: "#pspdfkit", document: "source.pdf", licenseKey: "YOUR_LICENSE_KEY" }).then((instance) => { instance.exportPDF({ outputFormat: { conformance: PSPDFKit.Conformance.PDFA_4F } }); });
The example below loads a PDF document in headless mode, exports it to a PDF/A document with conformance level PDF/A-2b, and downloads it in the client’s browser:
PSPDFKit.load({ container: "#pspdfkit", document: "source.pdf", licenseKey: "YOUR_LICENSE_KEY", headless: true }) .then((instance) => instance.exportPDF({ outputFormat: true }) ) .then(function (buffer) { const blob = new Blob([buffer], { type: "application/pdf" }); const objectUrl = window.URL.createObjectURL(blob); downloadPdf(objectUrl); window.URL.revokeObjectURL(objectUrl); }); function downloadPdf(blob) { const a = document.createElement("a"); a.href = blob; a.style.display = "none"; a.download = "output.pdf"; a.setAttribute("download", "output.pdf"); document.body.appendChild(a); a.click(); document.body.removeChild(a); }
When exporting a document, you have several options. Refer to our guides on flattening annotations and incremental saving for more details.
Auto saving can be configured for different scenarios and use cases. You can find more information in our auto save guide.