This guide will show you how to draw different shapes 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.
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.
Configure environment variables
UNIDOC_LICENSE_API_KEY with your API credentials from your UniCloud account.
How it works
Shapes in pdf are drawn using the provided methods of the creator object.
The following example code shows how different shapes are drawn using the creator package.
9-15 import necessary unipdf packages and other required libraries.
init function in lines
18-25 authenticates your request with
27-87 contains the main function that calls each function for drawing different shapes and handles respective errors returned by the functions.
Inside the main function the front page of the document is generated using
89-97 defines a
drawHeader function which is used for creating the header text displayed above each shape.
drawLine function for drawing a single line.
drawPolyLine function for drawing line based polygon.
drawRectangle function for drawing a single rectangle shape.
drawEllipse function for drawing ellipse.
161-248 the functions for drawing curve, Bezier curve,curve polygon and polygon shapes are defined.
Run the code
go run pdf_draw_shapes.go