Hyperlink

This guide will show you how to add hyperlinks and bookmarks to your own 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/hyperlink folder in the unioffice-examples directory.

cd unioffice-examples/document/hyperlink/

How it works

Lines 3-10 import the UniOffice packages and other required dependencies.

The init function in lines 12-19 authenticates your request with your UNIDOC_LICENSE_API_KEY.

In the main function, lines 21-57, a new document is created, followed by the creation of a style for hyperlinks in lines 26-32, where the color, underline, style name, and style properties, are sets.

Next, a paragraph is created as usual, but a bookmark is added to it in line 37. Lines 40-46 are used to apply the hyperlink style and add a new hyperlink to the document. Finally, in lines 50-54, a new hyperlink is added, with the previous bookmark set as the target, and text is added by inserting a run.

Run the code

Run this command to create a new document with a hyperlink to google and another that acts as a bookmark.

go run main.go

Sample output

Hyperlink template

Got any Questions?

We're here to help you.