Medication Schedule Report

In this guide the process of creating medical schedule report document using the creator template will be shown.

Before you begin

To follow along with this guide, you should first 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/medication-schedule-report folder in the unipdf-examples directory.

cd unipdf-examples/templates/medication-schedule-report

How it works

The import section in lines 9-23 imports all necessary libraries and packages. The init function loads your license key and authenticates your request.

In lines 35-56 the MedicalData object is defined to represent the data used in the template.

The main function defined in lines 58-136 is the entry point to program and it is where the template is drawn and written to file. In this function in lines 50-62 the creator object is instantiated, the page size and page margins are set. In lines 65-68 the main template is read using readTemplate("templates/main.tpl") by which the content of the template file is stored in to an io.Reader buffer. In lines 69-76 the arialBold and arialRegular fonts are loaded from files and stored in model.PdfFont type variables.

In lines 79-100 the template options object is defined where the necessary fonts and getColumnWidths function is contained. In lines 103-106 the jason data is is read using readData("data.json"). The template is drawn in lines 109-111 using c.DrawTemplate(mainTpl, medicationData, tplOpts). Here the main template, medication data and the template options are passed as parameters to the DrawTemplate function.

In lines 113-130 of the main function the code for drawing the footer is defined. Finally in line 133 the document is written to file.

The function readTemplate which is used to read the template file is defined in lines 139-151. In lines 154-167 the readData function is defined.

Run the code

To run the code use the following command.

go run pdf_medication_schedule.go

Sample Output

Preview of the two pages of the output document.

Medical Bill

Got any Questions?

We're here to help you.