Get PDFaid XMP metadata
This guide will show how to get pdfaid metadata from pdf file.
Before you begin
You should get your API key from your UniCloud account.
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 metadata
folder in the unipdf-examples directory.
cd unipdf-examples/metadata
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 3-13
imports unipdf packages and other necessary libraries.
The init
function in lines 15-22
loads your metered License API key from system environment prior to using the library to authenticates your request.
In lines 24-90
the main
function is defined. In lines 25-30
the number of command line arguments is checked and the input file is read from the command line argument.
The time taken to process the document is measured using the code in lines 33-37
. In lines 40-44
a new reader object is instantiated from the input file.
The document’s catalog metadata is extracted using reader.GetCatalogMetadata()
in lines 47-50
. A new core.PdfObjectStream
is created using core.MakeStream(data, nil)
in lines 53-56
.
The XMP document implementation is loaded using xmputil.LoadDocument(stream.Stream)
in lines 59-62
. In lines 71-76
the PDF/A ID name space is extracted using xmpDoc.GetPdfAID()
.
Run the code
go run pdf_get_xmp_pdfaid_metadata.go <input.pdf>