Documentation

This guide will explain how the documentation document is created by following the code in the templates example.

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/documentation folder in the unipdf-examples directory.

cd unipdf-examples/templates/documentation

How it works

The import section in lines 33-42 imports UniPDF packages and other necessary libraries. The init function in lines 33-42 loads your license key from the system environment and sets sets it metered key using license.SetMeteredKey. This is used to authenticate your request.

The main function in lines 44-76 draws the document and writes it to pdf file. In this function in lines 49-61 the functions drawContent, drawHeaders, drawFrontPage and drawTOC are used to create the document. The document is then written to file using c.WriteToFile in lines 73.

The function drawContent in lines 79-111 is used to render the main content templates. The drawHeaders function in lines 114-138 draws the header and footer sections of the document. The drawFrontPage function in lines 152-165 draws the front page of the document.

In lines 168-197 the function drawTOC is defined which is used to draw the table of contents. The createTplOpts function in lines 200-320 is used to create the template options object. The readTemplate function in lines 324-337 is used to read the template file.

The function newImageFromFile in lines 344-355 reads an image from file and returns model.Image object. The function xmlEscapeText is used to escape specified text by the parameter.

In lines 368-375 the variable chartColors which represents colors used by chart components, is defined.

The functions createPieChart, createLineChart, createBarChart, createStackedBarChart and CreateStackedBar defined from line 379 to 481 are used to create the corresponding type of charts as their name indicates.

The last function which is parseChartValMap defined in lines 490-519 is used parses a value map.

Run the code

Run the code using the following command.

go run pdf_templates_documentation.go

Sample Output

Preview of the document.

Documentation

Got any Questions?

We're here to help you.