Presentation Using Templates

This guide explains the process of creating a new presentation file from an existing template file using UniOffice.

Sample input

Template file sample template input

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 folder in the unioffice-examples directory.

cd unioffice-examples/presentation/use-template/

How it works

The import section imports the necessary UniOffice packages and Go libraries. The init function sets the license key.

The main function which is defined in lines 25-90, generates the modified presentation file. In this function the template presentation file is opened and presentation.Presentation object is instantiated.

Lines 29-31 print the layout information of the slides. The for loop in lines 34-36, remove the existing template slides. Line 37, obtains the layout of the template file using ppt.GetLayoutByName("Title and Caption") and saves it to a variable for later use.

In lines 37-44, a new slide is created from the template layout. Then the place-holder’s title and body of the template file are modified by updating the text content in lines 46-49. The remaining code i.e. lines 51-86, adds new slides with paragraph texts and other properties from the template layout. Then finally, the presentation is written to file in line 87 using ppt.SaveToFile("mod.pptx").

Run the code

Run this command to create the presentation from the template file.

go run main.go

Sample output

Modified presentation.

sample output

Terminal output.

0  LL  Title Slide / title
1  LL  Title and Content / obj
2  LL  Section Header / secHead
3  LL  Two Content / twoObj
4  LL  Comparison / twoTxTwoObj
5  LL  Title Only / titleOnly
6  LL  Blank / blank
7  LL  Content with Caption / objTx
8  LL  Picture with Caption / picTx
9  LL  Panoramic Picture with Caption / 
10  LL  Title and Caption / 
11  LL  Quote with Caption / 
12  LL  Name Card / 
13  LL  Quote Name Card / 
14  LL  True or False / 
15  LL  Title and Vertical Text / vertTx
16  LL  Vertical Title and Text / vertTitleAndTx

Got any Questions?

We're here to help you.