Simple Presentation
This guide will demonstrate the process of creating a simple presentation file.
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 presentation/simple
folder in the unioffice-examples
directory.
cd unioffice-examples/presentation/simple/
How it works
In the above example code, the import
section in lines 4-14
, imports the necessary Go libraries and UniOffice
packages are imported.
The init
function in lines 16-23
sets the metered license key using license.SetMeteredKey(os.Getenv(`UNIDOC_LICENSE_API_KEY`))
.
The main
function defined in lines 25-53
, creates the simple presentation file. First it creates a new presentation.Presentation
object using presentation.New()
. Then the for
loop in lines 28-48
adds slides with contents to the presentation using:
slide := ppt.AddSlide()
tb := slide.AddTextBox()
tb.Properties().SetGeometry(dml.ST_ShapeTypeStar10)
tb.Properties().SetWidth(3 * measurement.Inch)
pos := measurement.Distance(i) * measurement.Inch
tb.Properties().SetPosition(pos, pos)
tb.Properties().SetSolidFill(color.AliceBlue)
tb.Properties().LineProperties().SetSolidFill(color.Blue)
p := tb.AddParagraph()
p.Properties().SetAlign(dml.ST_TextAlignTypeCtr)
r := p.AddRun()
r.SetText("gooxml")
r.Properties().SetSize(24 * measurement.Point)
The slide is validated in line 49
. Finally, the presentation document is written to file in line 52
.
Run the code
Run this command to generate the presentation file.
go run main.go