Get Page Info

This guide shows you how to get info about a page(s) in a PDF. The sample output contains information about the page, including its rotation, media box, height and width.

Sample input

This example accepts an input path to the PDF and an optional page number to get its info.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniPDF SDK, follow our instructions to set up a local development environment[add a link to the getting started guide].

Project setup

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

Change into the repository directory and navigate to the pages folder.

cd unipdf-examples/pages

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

Lines 10-18 import the UniPDF packages and other required dependencies.

Lines 20-27 authenticate your request with your UNIDOC_LICENSE_API_KEY with the init function.

The main function in lines 29-55 accepts at least one argument: an input path to the PDF and an optional page number to get its info. The main function passes the arguments as input to the printPdfPageProperties function.

Lines 57-95 create the printPdfPageProperties function. It reads each page from the PDF, if no page number was provided and output its properties to the terminal.

Run the code

Run this command to get page(s) info about the PDF. This will also get all the required dependencies to run the program.

go run pdf_page_info.go path_to_file.pdf [optional page number]  

Sample output

The page info for the specified page or all pages in the PDF will be displayed on the terminal. You should get something similar to this.

# these values are in point(the SI unit in UniPDF)
Page rotation: 0

Page mediabox: &{Llx:0 Lly:0 Urx:612 Ury:792}

Page height: 792.000000

Page width: 612.000000

Got any Questions?

We're here to help you.