Boarding Pass

In this guide creating a sample boarding pass using creator template will be shown.

Before you begin

If you don’t already have it, you should get your API key from your UniCloud account.

If this is your first time using UniPDF SDK, follow this guide to setup 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 templates/boarding-pass folder in the unipdf-examples directory.

cd unipdf-examples/templates/boarding-pass

How it works

The import section 10-25 imports the UniPDF packages and other necessary libraries.\

The init function in 27-36 loads your license key and authenticates your request.

The main function defined in lines 38-94 is the entry point to the program. Here the creator object is instantiated and the page margins are set in lines 39 and 40 respectively. In lines 43-52 the template file and json file are read. The creator.TemplateOptions object is created in lines 61-84. Finally the template is drawn in line 86 using c.DrawTemplate and written to file using c.WriteToFile in line 91.

The readTemplate function in lines 98-111 reads the template file. The createQRCode function in lines 115-132 creates qr code and returns it as model.Image object. The json file which contains the data used for boarding pass is decoded in to Pass object using readBoardingPassData function which is defined in lines 135-148.

In lines 168-171 the Airport object which represents the data used for the boarding pass is defined.

Run the code

Run the code using the following command.

go run pdf_boarding_pass.go

Sample Output

Boarding Pass

Got any Questions?

We're here to help you.