Medical Bill
This guide will show you how to create a medical bill document using creator templates from the creator package of UniPDF.
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/medical-bill folder in the unipdf-examples directory.
cd unipdf-examples/templates/medical-bill
How it works
The import in lines 10-22 imports UniPDF packages and other necessary libraries.
The init function defined in lines 24-33 authenticates you request by loading your license key from environment variable.
In lines 35-91 the main function of the program is defined. In this function In this function in lines 40-43 the template file is read using readTemplate("templates/main.tpl"). In lines 46-49 the json data is read using readBillData("medical_bill.json"). The template options which contains helpful functions and other data is defined using creator.TemplateOptions in lines 52-72. The data is defined in lines 74-81. The template is drawn in line 83-85. And finally the pdf document is drawn to file using c.WriteToFile("unipdf-medical-bill.pdf") in line 88-91.
The functions readTemplate and readBillData defined in lines 95-124 are used to read the template file and the json data respectively.
The Bill data defined in 127-133 represents the bill data used for the template. The Guarantor, MedicalService, ServiceItem objects defined in lines 136-157 represents data that are part of the Bill data.
Run the code
Run the code using the following command.
go run pdf_concert_ticket.go
Sample Output
Document preview.
