Concert Ticket

This guide will explain how to create a sample concert ticket using creator templates.

Before you begin

Before trying to follow this guid, 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/concert-ticket folder in the unipdf-examples directory.

cd unipdf-examples/templates/concert-ticket

How it works

In lines 27-39 Field and Ticket objects are defined.

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 in lines 51-94 is the entry point the program and runs the other functions to create the document. In line 52-53 the creator object is instantiated and the margin of the page are set. In lines 56-71 a qr code image is created, the json data and the template file are read. The template Options object is created using creator.TemplateOptions in lines 74-84. In line 86 the template is drawn using Creator.DrawTemplate. In line 91 using c.WriteToFile("unipdf-ticket.pdf").

The createQRCode function defined in lines 117-130 creates a qr code image using the data given in text parameter. The readTemplate function reads the template file returns an io.Reader type buffer containing the template data. The readTemplateData function defined in lines 133-149 reads the json data and decodes it to Ticket object.

Run the code

Run the code using the following command.

go run pdf_concert_ticket.go

Sample Output

Concert Ticket

Got any Questions?

We're here to help you.