Presentation with Custom Paragraph Properties
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 presentation/complex
folder in the unioffice-examples
directory.
cd unioffice-examples/presentation/complex/
How it works
In the above sample code, the necessary packages are imported in lines 4-13
.
Then the metered license key is set inside the intit
function, i.e. in lines 15-22
.
The main
function which contains the code used for generating the desired document is defined in lines 26-80
.
In this function, a new presentation.Presentation
object is created in line 27
using presentation.New()
. Then in lines 29-37
, an image is loaded from file and added to the Presentation
object using:
imgColor, err := common.ImageFromFile("gophercolor.png")
irefColor, err := ppt.AddImage(imgColor)
In line 39
, a new slide is created using ppt.AddSlide()
. Then the image is added to the slide in lines 41-43
. In line 45
a new presentation.TextBox
is created using slide.AddTextBox()
. The text anchoring and paragraph alignments are set afterwards in lines 46-49
.
From line 55
though line 60
, the properties of the TextBox
objects are set using:
tb.Properties().SetGeometry(dml.ST_ShapeTypeChevron)
tb.Properties().SetFlipHorizontal(true)
tb.Properties().SetSolidFill(color.LightBlue)
tb.Properties().LineProperties().SetWidth(0.125 * measurement.Inch)
tb.Properties().LineProperties().SetSolidFill(color.DarkBlue)
tb.Properties().SetPosition(2.5*measurement.Inch, 0.5*measurement.Inch)
Another TextBox
is created in lines 62
. Then the properties and contents of the TextBox
are set using the for loop in lines 64-74
.
Finally, the presentation is saved to a file in line 79
using ppt.SaveToFile("complex.pptx")
.
Run the code
Run this command to create the presentation using the example code.
go run main.go