Get Media Management Metadata

This guide will walk you through the example of getting custom XMP 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 following example code gets metadata from pdf file.

The import section imports necessary unipdf packages and other libraries. The init function loads UNIDOC_LICENSE_API_KEY from system environment and authenticates your request. The main function which gets the media management XMP metadata is defined in lines 24-111.

In lines 25-30 of the main function reads the input file from the command line arguments and sets to the the variable inputPath. The code in lines 33-37 measures the time taken to finish running the program. In lines 40-44 a new model.PdfReader is constructed using the given file path. Then the catalog metadata is retrieved in lines 47-50 using reader.GetCatalogMetadata(). The code in lines 53-56 gets the PdfObjectStream version of the metadata object.

In line 59 the XMP document is loaded using xmputil.LoadDocument(stream.Stream). Then media management metadata is extracted using xmpDoc.GetMediaManagement() in lines 65-69.

Finally in lines 72-111 various fields and information are printed.

Run the code

go run pdf_get_xmp_media_management_metadata.go <input.pdf>

Got any Questions?

We're here to help you.