Get XMP Metadata
This guide will show you how to get pdf XMP meta data from a 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. This authenticates your request.
In lines 24-90
the main
function is defined.
The input file is parsed from the command line argument in lines 25-30
. In lines 33-37
the time taken to finish the process is measured. In lines 40-44
a new reader object is constructed form the input file.
The XMP metadata is extracted from the pdf catalog metadata in lines 47-50
. In lines 53-56
the stream object is retrieved from XMP metadata objects. The XMP document is loaded in line 59-62
. The code in lines 66-70
gets the pdf info using xmpDoc.GetPdfInfo()
. The pdf info dictionary is extracted in lines 72-80
. Finally in lines 82-90
the pdf version and the copy right information are extracted and printed.
Run the code
go run pdf_get_xmp_pdf_metadata.go <input.pdf>