Apply PDF/A-1 Standard

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

Before you begin

First things first, 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 following example code applies a PDF/A standard to a pdf file.

UniPDF packages and other necessary go libraries are imported in the import section in lines 9-18. Your metered license key is loaded from the system environment using license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`)) in the init function defined in lines 21-28.

The main function defined in lines 30-66 applies the standard and writes the document to file. In lines 31-37 the path of the input and output files is read from the command line arguments. Starting time is initialized using time.Now() in line 40. In lines 43-47 a new pdf reader is instantiated. A writer is instantiated from the reader. Then the standard is applied using pdfWriter.ApplyStandard(pdfa.NewProfile1B(nil)) in line 56. The processed document is then written to file using pdfWriter.WriteToFile(outputPath). And finally the duration of time it took to process the file is measured and printed in lines 64-65.

Run the code

Run this command to create apply the PDF/A standard on the <input.pdf> file.

go run pdf_apply_standard.go <input.pdf> <output.pdf>

Output

Processing time: 23.17 ms

PDF/A file

Got any Questions?

We're here to help you.