Apache POI XSLF  


Open Source Java API for PPTX Presentations

Create, Edit and Merge Microsoft PowerPoint OOXML Presentations via Java Library.

Apache POI XLSF is Java implementation for reading, creating or editing PowerPoint PPTX files. It provides the necessary functionality for working with PowerPoint 2007 OOXML file format, enabling developers to extract data such as text, images, embedded objects & more from PowerPoint PPTX presentations. Developers can also add shapes to a slide, manage hyperlinks & images, add videos, and convert PPTX to SVG.

Previous Next

Getting Started with Apache POI XLSF

First of all, you need to have the Java Development Kit (JDK) installed on your system. If you already have it then proceed to the Apache POI's download page to get the latest stable release in an archive. Extract the contents of the ZIP file in any directory from where the required libraries can be linked to your Java program. That is all!

Referencing Apache POI in your Maven-based Java project is even simpler. All you need is to add the following dependency in your pom.xml and let your IDE fetch and reference the Apache POI Jar files.

Apache POI Maven Dependency

<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->

Java API to Create New Presentations & Append Slide to Existing File

Apache POI XLSF enables computer programmers to create new PowerPoint presentations in PPTX file format from scratch. Developers can also transform an existing presentation according to their needs. It provides the ability to read & modify the existing presentations as well as append slides to the existing presentation according to their need.

Create a Slide - Java

// create a new PPTX file
FileOutputStream fileOutputStream = new FileOutputStream(new File("Slide.pptx"));
// create a new slide show
XMLSlideShow xmlSlideShow = new XMLSlideShow();
// save file

Create New Slide from a Predefined Slide Layout in Java Apps

Apache POI XLSF API has included support for adding new slides from a predefined slide layout inside PPTX presentation. Slide layouts contain formatting, positioning, and placeholder boxes for all of the content that appears on a slide.  PowerPoint presentations have several slide layouts; first of all, you need to see which slide layouts are available for use. There are different slide masters and in each slide master, there are several slide layouts. 

Title Layout Slide - Java

//  create a new PPTX file
FileOutputStream fileOutputStream = new FileOutputStream(new File("Slidelayout.pptx"));
// create a new slide show
XMLSlideShow xmlSlideShow = new XMLSlideShow();
// initialize slide master object
XSLFSlideMaster xslfSlideMaster = xmlSlideShow.getSlideMasters().get(0);
// set Title layout
XSLFSlideLayout xslfSlideLayout = xslfSlideMaster.getLayout(SlideLayout.TITLE);
// create a new slide with title layout
XSLFSlide xslfSlide = xmlSlideShow.createSlide(xslfSlideLayout);
// select place holder
XSLFTextShape xslfTextShape = xslfSlide.getPlaceholder(0);
// set title
// save file
// close stream

Merge Multiple PPTX Presentations together using Java

Do you have multiple PPTX presentations that you want to combine into one presentation? Apache POI XLSF APIs can surely help you and enables Java developers to merge their multiple PPTX files together.

Merge Slides - Java

// create a new PPTX file
FileOutputStream fileOutputStream = new FileOutputStream("MergegSlide.pptx");
// select two PPTX files
String[] inputFiles = {"Slide.pptx", "SlideLayout.pptx"};
// create a new slide show
XMLSlideShow slideShow = new XMLSlideShow();
// merge slides
for(String file : inputFiles){
    FileInputStream inputstream = new FileInputStream(file);
    XMLSlideShow xmlSlideShow = new XMLSlideShow(inputstream);
    for(XSLFSlide srcSlide : xmlSlideShow.getSlides()) {
// saving file
// close stream