Add Side Note to a Page’s Margin
Add a sidenote to a page’s left or right margin using the .PageFinalize
function while creating the PDF.
The .pageFinalize
function is called on each PDF page in the final stage of creation and appends a paragraph at 90 degrees with custom text.
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
Change into the repository directory and navigate to the pages
folder.
cd unipdf-examples/pages
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 9-17
import the UniPDF packages and other required dependencies.
Lines 19-26
authenticate your request with your UNIDOC_LICENSE_API_KEY
with the init function.
The main function in lines 28-102
creates a new PDF, appending a sidenote to each page margin. The created PDF is saved to the output path, page_side_notes.pdf
.
Run the code
Run this command to add a sidenote to each page’s margin. This will also get all the required dependencies to run the program.
go run pdf_page_side_note.go
Sample output
There is text on each page’s left or right margin in the PDF. In this example, you can see the text: Page 1/2
at the page’s right margin.