Trade Confirmation

This guide will show the process of creating a sample trade confirmation document using creates template.

Before you begin

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

cd unipdf-examples/templates/trade-confirmation

How it works

The following code shows how a trade confirmation document is created using the template.

The import section in lines 10-22 imports some UniPDF packages and other necessary libraries. The init function loads your license key from the system environment which is used to authenticate library request.

The main function which is the entry point to the program is defined in lines 35-88. In lines 36-37 the creator object is instantiated and the page margins are set using c.SetPageMargins(50, 50, 25, 25). The template is read in lines 46-49. In lines 52-72 the template options object is instantiated. The template is then drawn in lines 74-78 using c.DrawTemplate(mainTpl, data, tplOpts). Finally the pdf document is written to file in lines 85-87 using the code c.WriteToFile("unipdf-trade-confirmation.pdf").

The readTemplate function in lines 92-105 is defined where the template file is read and an io.Reader buffer is returned. In lines 108-121 the Trade object which represents a sample trading is defined. In lines 124-141 a TradeCalculation object which is part of the Trade object is defined.

In lines 144-157 the function readTradeData is defined. This function reads the json data which contains the trading data and decodes it to TradeData.

Run the code

tTo run the code use the following command.

go run pdf_trade_confirmation.go

Sample Output

Trade Confirmation

Got any Questions?

We're here to help you.