Java/ Split PowerPoint Document into Individual Slides
This article will introduce a time-saving method to split a PowerPoint document into multiple individual slides in Java application.
Tools Used:
● Free Spire.Presentation for Java
● IntelliJ IDEA
Installation
Method 1: Download the Free Spire.Presentation for Java and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.
Method 2: You can also add the jar dependency to your maven project by adding the following configurations to the pom.xml.
<repositories>
<repository>
<id>com.e-iceblue</id>
<name>e-iceblue</name>
<url>http://repo.e-iceblue.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>e-iceblue</groupId>
<artifactId>spire.presentation.free</artifactId>
<version>3.9.0</version>
</dependency>
</dependencies>
The test PowerPoint document which contains 3 slides is shown as below:
Code Snippet
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class SplitPowerPoint {
public static void main(String[] args) throws Exception {
//Load the sample PowerPoint file
Presentation ppt = new Presentation();
ppt.loadFromFile("test1.pptx");
//Loop through the slides
for (int i = 0; i < ppt.getSlides().getCount(); i++)
{
//Create an instance of Presentation class
Presentation newppt = new Presentation();
//Remove the default slide
newppt.getSlides().removeAt(0);
//Select a slide from the source file and append it to the new document
newppt.getSlides().append(ppt.getSlides().get(i));
//Save to file
newppt.saveToFile(String.format("output/result-%d.pptx",i), FileFormat.PPTX_2013);
}
}
}
Output: