Division Layout

This guide will explain the steps to create a table with a division layout.

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 set up a local development environment.

Project setup

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.

cd unipdf-examples/tables

Configure environment variables

Replace the UNIDOC_LICENSE_API_KEY with API credentials from your UniCloud account.

Linux/Mac

export UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

Windows

set UNIDOC_LICENSE_API_KEY=PUT_YOUR_API_KEY_HERE

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.

The init function defined in Lines 20-27 loads your metered License API key before using the library.

In lines 29-141 the 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 c.NewDivision(). 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 124-130.

Finally in lines 133-140 the table is drawn and the document is written to unipdf-tables-division-layout.pdf file.

Run the code

Run the code using the following command.

go run pdf_tables_division_layout.go

Sample output

After running code the output should be like this.

PDF table colspan

This is the first page of the document.

Got any Questions?

We're here to help you.