This guide will explain the steps to create a table with a division layout.
Before you begin
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
tables folder in the unipdf-examples directory.
Configure environment variables
UNIDOC_LICENSE_API_KEY with API credentials from your UniCloud account.
How it works
Basically the division layout is made by creating a new division object and then adding the respective contents to the divisions, which in this case are images. Then the divisions are added to table cells.
This is shown in the following example code.
In the above code in lines
10-18 unipdf packages and other libraries are imported.
init function defined in Lines
20-27 loads your metered License API key before using the library.
main function where everything happens is defined. In this function in Lines
35-48 a new creator object is instantiated, the margins and the optimizer are set. In line
83 two divisions named left division and right division are created using
The loop in lines
84-112 iterates through each image and adds it to the right division if
i is even, otherwise it adds it the left division.
The left column of the table is created in lines
115-121 and the right column in lines
Finally in lines
133-140 the table is drawn and the document is written to
Run the code
Run the code using the following command.
go run pdf_tables_division_layout.go
After running code the output should be like this.
This is the first page of the document.