Validate PDF/A-2 Standard

This guide will show how to validate PDF/A-2 standards to a file using UniPDF library.

Before you begin

Before starting to follow along with this guide you should get your API key from your UniCloud account.

If you don’t have a development environment setup, That is if this is your first time using UniPDF SDK, follow this guide to set up a local development environment.

Project setup

Clone the project repository

In your terminal, clone examples repository. It contains the Go code we will be using for this guide.

git clone https://github.com/unidoc/unipdf-examples.git

Navigate to the pdfa folder in the unipdf-examples directory.

cd unipdf-examples/pdfa

Configure environment variables

Replace the UNIDOC_LICENSE_API_KEY with your API credentials from your UniCloud account.

Linux/Mac

export UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

Windows

set UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

How it works

The import section in lines 9-18 imports the necessary UniPDF packages. The init function defined in lines 20-27 loads the metered license key and authenticates your requests.

The main function contains the code used to validate the PDF/A-2 standard. The path of the input file is read from the command line arguments. A new CompliancePdfReader is instantiated from the input using model.NewCompliancePdfReader(inputFile) in line 47. A list of different PDF/A-2 standard profiles is instantiated in lines 53-57. The loop in lines 60-64 iterates through each standard and runs validation using standard.ValidateStandard(detailedReader).

Run the code

Run this command to validate the PDF/A-2 standard on the <input.pdf> file.

go run pdfa2_validate_standard.go <input.pdf>

Output

The following message is a sample output printed on the terminal after running the code with sample input file.

Processing time: 22.19 ms

PDF/A-2 verapdf validation report

The following image shows a validation report from verapdf for the same file.

PDF/A-2 validation

Got any Questions?

We're here to help you.