Add Ellipse Annotation

This guide will show you how to add an ellipse annotation to a specific page in a PDF document without altering its original content.

The x, y, height, and width coordinates are in the PDF coordinate system, where (0,0) is in the lower-left corner of the page.

Sample Input

Page to add Ellipse Annotation

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 the examples repository. It contains the Go code we will be using for this guide.

git clone

Navigate to the annotations folder in the unipdf-examples directory.

cd unipdf-examples/annotations

How it works

Lines 11-21 import the UniPDF packages and other required dependencies.

The init function in lines 23-30 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function in lines 32-79 validates your input and passes it as arguments to the annotatePdfAddEllipseAnnotation function.

Lines 81-142 define the annotatePdfAddEllipseAnnotation function, which accepts inputPath, pageNumber, outputPath, x,y, width and height as parameters. CircleDef initializes the annotator.CircleAnnotationDef struct and assigns values to the ellipse properties, which can be changed as needed.

The function reads the input PDF, creates the ellipse at the specified location and writes the annotated PDF to the output path.

Run the code

Run this command to add an ellipse annotation to the specified page in a PDF. This will also get all the required dependencies to run the program.

go run pdf_annotate_add_ellipse.go input.pdf <page> <x> <y> <width> <height> output.pdf

# to reproduce the sample output
go run pdf_annotate_add_ellipse.go input.pdf 1 40 87 50 50 output.pdf

Sample output

Open the output PDF with a PDF viewer and you will see an ellipse(circle) drawn on the specified location and page. Page with Ellipse Annotation

Got any Questions?

We're here to help you.