Draw Lines
This guide will show how to draw multiple lines on pdf files.
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 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 drawing
folder in the unipdf-examples directory.
cd unipdf-examples/drawing
Configure environment variables
Replace the UNIDOC_LICENSE_API_KEY
with your 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
Lines are drawn using the Creator.NewLine
function provided in the creator package.
The following example code shows how lines are drawn using the creator package.
Lines 9-16
import necessary unipdf packages and other required libraries.
The init
function in lines 18-25
authenticates your request with UNIDOC_LICENSE_API_KEY
.
In Lines 27-85
the main function is defined where a new creator object is instantiated and all the line drawing functions are called. Writing the pdf document to a file is also done here in line 80
. The front page of the document and the table of content is created here.
Lines 87-120
define a function for creating lines using absolute positioning.
Lines 122-168
define a function for creating lines using relative positioning.
Lines 178-227
draw lines inside Division
components.
All the lines are created inside a creator.VectorDrawable
component and then added to Division
component one by one. Finally the division is drawn using Creator.Draw()
function, which is done in line 226
.
Lines 229-313
draw lines inside a Table
.
In this function all the lines are added to a table cell using cell.SetContent(content)
. Finally the table is drawn by calling c.Draw(table)
in line 312
.
Lines 315-322
define a function for creating a new paragraph object using the creator
package.
A new paragraph is created using Creator.NewStyledParagraph()
function.
Lines 324-325
define a function for creating a new line using the necessary parameters.
Lines 350-360
define a function for creating a creator.Margins
using the given parameters.
Run the code
go run pdf_draw_lines.go