Presentation with an Image from Template
This guide explains the process of creating a presentation with an image from a template 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/use-template-with-image folder in the
How it works
import section, as its name implies, imports the necessary
UniOffice packages and other Go libraries.
init function, which is defined in lines
4-15, sets the metered license key before running the
main function is defined in lines
26-104. In this function, the template presentation is instantiated from the template file in lines
The for loop
38-43, cleans up the existing slides from the template. In line
46, a new layout is obtained from the template presentation using
ppt.GetLayoutByName("Picture with Caption"). The required image is loaded from local file and added to the presentation in lines
A new slide is created in line
ppt.AddDefaultSlideWithLayout(layout). Then all the contents are added to the slides by injecting them to the placeholders. In line
94, the presentation is validated using
Finally, the presentation is written to file in line
Run the code
Run this command to create the presentation file.
go run main.go
success! took 0.014773875 seconds