Get PDF Object

This guide will walk you through the process of the getting a specific PDF object using object number.

Sample Input

Sample 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.

Clone the project repository

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

git clone

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

cd unipdf-examples/analysis

How it works

In the example attached above, the import section in lines 10-18, imports all the necessary UniPDF packages and other Go libraries. The init function defined in lines 20-27, loads the metered API key and sets the license prior to using the UniPDF packages.

The main function defined in lines 29-54, gets the PDF object by using the inspectPdfObject function. In this function inputPath is obtained from the command line arguments in line 36. Then in line 49, the PDF object is obtained and printed using inspectPdfObject(inputPath, objNum).

In lines 56-93, the inspectPdfObject function is defined. In this function a new PdfReader is created using model.NewPdfReaderFromFile(inputPath, nil) in line 57. The desired object is obtained from the object number using pdfReader.GetIndirectObjectByNumber(objNum) in line 74. In line 81, the object is decoded if necessary.

Run the code

Run the code using the following command:

go run pdf_get_object.go input.pdf [num]

Sample output

The following output displays the PDF object with object number 10.

Input file: sample.pdf
Object 10: IObject:10
Dict("Creator": Rave (, "Producer": Nevrona Designs, "CreationDate": D:20060301072826, )

Got any Questions?

We're here to help you.