DEV Community

CodeSharing
CodeSharing

Posted on

1

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>
Enter fullscreen mode Exit fullscreen mode

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);
    }
}
Enter fullscreen mode Exit fullscreen mode

CopyPPT

API Trace View

Struggling with slow API calls? 👀

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more