Open Source Go Library to Create MS PowerPoint PPTX Presentations
A Powerful Open Source GO API to Create Read, Write, & open Microsoft® PowerPoint PPTX Presentation with ease.
What is Unioffice?
Unioffice is an open-source pure go library that gives software developers the capability to create and parse Microsoft Presentation documents inside their own Go applications. Using the API, you can create PPTX fairly fast, save it quickly because of no reflection usage and while reading the PPTX, it can take a little more time.
The open-source unioffice library supports several important features related to PowerPoint creation, such as creating a new PowerPoint from the template, add text boxes in it, and insert images.
Getting Started with Unioffice
The recommended way to install the Unioffice into your project is by using Github. Please use the following command for a smooth installation.
Install Unioffice via GitHub
go get github.com/unidoc/unioffice/
go build -i github.com/unidoc/unioffice/...
Add Images in PPTX via Go API
The Open source library unioffice allows computer programmers to insert images in a PPTX file inside their own Go applications. It gives you the capability to create a new PPTX, insert your image in it and save the document. By using the following lines of code, you can easily insert images in your PPTX document.
How to Insert Images in PPTX GO?
- Create a new presentation by using presentation.New() method
- Load image using ppt.AddImage() method and pass path to the image as a string
- Create a new slide using ppt.AddSlide() method
- Add image in the slide by using slide.AddImage() method and pass image object as parameter
- Set image width and height in inches
- Validate the document and save it in PPTX format
Insert Images via Free GO API
ppt := presentation.New()
defer ppt.Close()
irefColor, err := ppt.AddImage("fileformat.png")
if err != nil {
log.Fatal(err)
}
slide := ppt.AddSlide()
ibColor := slide.AddImage(irefColor)
ibColor.Properties().SetWidth(2 * measurement.Inch)
ibColor.Properties().SetHeight(irefColor.RelativeHeight(2 * measurement.Inch))
if err := ppt.Validate(); err != nil {
log.Fatal(err)
}
ppt.SaveToFile("image.pptx")