Copy Slides from One Presentation to Another Using Java
This article will introduce how to copy slides from one PowerPoint presentation to another programmatically using Free Spire.Presentation for Java.
Import jar dependency (2 Methods)
● Download the free library and unzip it. Then add the Spire.Presentation.jar file to your project as dependency.
● 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>
Sample Code
import com.spire.presentation.FileFormat;
import com.spire.presentation.Presentation;
public class CopySlides {
public static void main(String[] args) throws Exception {
//Create a Presentation object to load the first document
Presentation pptOne= new Presentation();
pptOne.loadFromFile("test1.pptx");
//Create a Presentation object to load the second document
Presentation pptTwo = new Presentation();
pptTwo.loadFromFile("input1.pptx");
//Insert the specific slide of the first document to the specified position on the second document
pptTwo.getSlides().insert(1,pptOne.getSlides().get(0));
//Append the specific slide of the first document to the end of the second document
pptTwo.getSlides().append(pptOne.getSlides().get(2));
//Save the second document to file
pptTwo.saveToFile("CopySlides.pptx", FileFormat.PPTX_2013);
}
}