Watermark Text

This guide will demonstrate how to add text as a watermark in a Word document.

Before you begin

You should get your API key from your UniCloud account.

If this is your first time using UniOffice 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 https://github.com/unidoc/unioffice-examples

To get the example navigate to the path document/watermark-text folder in the unioffice-examples directory.

cd unioffice-examples/document/watermark-text

How it works

Lines 4-9 import the UniOffice packages and other required dependencies.

The init function in lines 11-18 authenticates your request with your UNIDOC_LICENSE_API_KEY.

The main function runs from line 22 to 42 and accomplishes the following tasks: it creates a new document, adds a paragraph and a run, and inserts text multiple times using a loop.

At line 33, a text watermark is added using the AddWatermarkText function with the text “TEST”. Furthermore, in the subsequent lines, it is configured to be in bold and not in italics.

Lastly, at line 41, the file is saved.

Run the code

Execute this command to create the file with a watermark text.

go run main.go

Sample output

Watermark Text

Got any Questions?

We're here to help you.