Aviation Checklist

This guide will show you how to create a sample aviation checklist document using the creator template.\

Before you begin

In order to follow along this guide, you should get your API key from your UniCloud account. If this is your first time using UniPDF SDK, you should 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/aviation-checklist folder in the unipdf-examples directory.

cd unipdf-examples/templates/aviation-checklist

How it works

Here is a step by step explanation of the above example code.

The import section in lines 10-26 imports UniPDF packages and other necessary libraries.

The init function defined in lines 28-37 adds a license key to authenticate library request.

The main function defined 35-88 creates the document and writes it to pdf file. In lines 37 the margins of the pdf pages is set using c.SetPageMargins(50, 50, 25, 25). The template file and the json file are read in lines 40-49. The template options is created in lines 52-72 using &creator.TemplateOptions. The data used in the template to create the document is defined in lines 74-78.

The template is drawn using c.DrawTemplate in lines 80-82. Finally the pdf document is written to file in lines 85-88. The readTemplate function in lines 147-160 reads the template file. The readChecklistData reads the data given in a jason and decodes it to Checklist object. The Checklist object which represents check list data is defined in lines 179-183. The Checks and CheckItem objects which are defined in lines 186-196 are part of the Checklist object.

The DisplayText in lines 199-231 computes the display properties of the text and returns checklist label, separator, and value. In lines 241-248 the width of a given character is calculated using getRuneWidth function which is used in side the DisplayText function.

Run the code

Use the following command to run the code.

go run pdf_aviation_checklist.go

Sample Output

The following image shows a preview of the pages of the output document. Airplane Ticket

Got any Questions?

We're here to help you.