Adding Borders to Paragraphs
This guide will show you how to add borders to paragraphs and control the type, size and color.
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
Navigate to the path
document/paragraph-borders folder in the unioffice-examples directory.
How it works
14-22 import the UniOffice packages and other required dependencies.
The init function in lines
24-31 authenticates your request with your
In the main function, which spans from line
33 to 94, a new document is created along with two paragraphs, one styled as
Title and the other as
Heading1. Each of these paragraphs is given a Run containing text. The borders of the last paragraph are obtained using the
Borders function. Subsequently, in line
SetBottom function is used to add a bottom border to the paragraph, specifying the type of border, color, and size.
Following this, another paragraph with a different Run is created to add another bottom border, but this time the border type is changed to
BorderSingle in line
61 to 68, two new paragraphs are added, with the first one styled as
Heading1, and each of them is given a Run. For the second paragraph, all borders are added using the
SetAll function after obtaining their borders with
Borders. These borders are of type
Finally, the same two paragraphs are added again, and from lines
84 to 88, all borders are added to the last paragraph using a separate function for each side:
SetBottom. Each of these borders has a different style, including
BorderTriple. The file is then saved in line
Run the code
Execute this command to generate a Word page with several paragraphs, each featuring various border styles.
go run main.go