Get PDF Object
This guide will walk you through the process of the getting a specific PDF object using object number.
Sample Input
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 https://github.com/unidoc/unipdf-examples.git
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-17
, imports all the necessary UniPDF packages and other Go libraries. The init
function defined in lines 19-26
, loads the metered API key and sets the license prior to using the UniPDF packages.
The main
function defined in lines 28-59
, prints the PDF object details by using the PrintPdfObject
function. First, in the main
function inputPath
is obtained from the command line arguments in line 36
. Then, a new PdfReader
is created using model.NewPdfReaderFromFile(inputPath, nil)
in line 48
.
As a result, in line 54
, the PDF object is obtained and printed using PrintPdfObject
of PdfReader
.
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
*core.PdfObjectDictionary
Dict("Creator": Rave (http://www.nevrona.com/rave), "Producer": Nevrona Designs, "CreationDate": D:20060301072826, )