Lab Results

This guide will show how to create a sample lab result document using the creator templates.

Before you begin

Before you begin, 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/lab-results folder in the unipdf-examples directory.

cd unipdf-examples/templates/lab-results

How it works

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

The import section in lines 10-21 import the necessary packages and libraries. The init function loads your license key and authenticates your request. The main function in lines 34-104 creates the document using the creator object and writes it to file. In this function in lines 39-48 the main template and the jason data are read using the readTemplate and readResultData functions. The TemplateOptions object created in lines 51-61 add infoColor function which is used to color the information text. In line 63-65 the template is drawn using c.DrawTemplate. In lines 93-98 the header and the footer section is drawn. Finally the document is written to file using the following code.

if err := c.WriteToFile("unipdf-lab-results.pdf"); err != nil {
		log.Fatal(err)
	}

The function readTemplate in lines 108-121 is used to read the template. The function readResultData defined in lines 124-137 reads the data given in a jason file and decodes it to LabResults objects.

In lines 140-205 the Patient, Specimen, Physician, TestResult objects and other necessary variables are defined.

Run the code

Run the code using the following command.

go run pdf_lab_results.go

Sample Output

Preview of the pages of the output document.

Lab Results

Got any Questions?

We're here to help you.