Operate the Presentation Slides Using Java
Tags: java, powerpoint, api
Published: 2021-06-11 06:51:14

PowerPoint is an efficient tool for people to display the information and make a presentation. This article will demonstrate how to operate the presentation slides programmatically using Free Spire.Presentaion for Java. The follwing examples include adding new slide in PowerPoint document, removing an existing slide, hiding slide from a PowerPoint document and changing the Slide Order within a Presentation.

**Import jar dependency** (2 Methods)
● Download the [Free Spire.Presentation for Java](https://www.e-iceblue.com/Download/presentation-for-java-free.html) 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.
```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>
```

**Add 2 new slides to an existing PowerPoint document:**
```java
import com.spire.presentation.*;

public class AddSlides {
    public static void main(String[] args) throws Exception {

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("input1.pptx");

        //add new slide at the end of the document
        presentation.getSlides().append();

        //insert a blank slide before the second slide
        presentation.getSlides().insert(1);

        //Save the document
        presentation.saveToFile("output/AddSlide.pptx", FileFormat.PPTX_2010);
    }
}
```
![Add Slides](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/delx2oiz7xx1mfp9pen2.jpg)

**Hide a slide that we don't want to present to audiences without deleting it:**
```java
import com.spire.presentation.*;

public class HideSlides {
    public static void main(String[] args) throws Exception {
        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("input1.pptx");

        //Hide the second slide
        presentation.getSlides().get(1).setHidden(true);

        //Save the document
        presentation.saveToFile("output/HideSlide.pptx", FileFormat.PPTX_2010);
    }
}
```
![Hide Slide](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fn2i494245rys23eud40.jpg)

**Delete a slide from the PowerPoint document:**
```java
import com.spire.presentation.*;

public class DeleteSlides {
    public static void main(String[] args) throws Exception {

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("input1.pptx");

        //Remove the third slide
        presentation.getSlides().removeAt(2);

        //Save the document
        presentation.saveToFile("output/Removeslide.pptx", FileFormat.PPTX_2010);
    }
}
```
![Delete Slide](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z98hvxvyekqjftpamhev.jpg)

**Change the slide order within a PowerPoint document:**
```java
import com.spire.presentation.*;

public class SlidesOrder {
    public static void main(String[] args) throws Exception {

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("input1.pptx");

        //Move the first slide to the second slide position
        ISlide slide = presentation.getSlides().get(0);
        slide.setSlideNumber(2);

        //Save the document
        presentation.saveToFile("output/Reorderslide.pptx", FileFormat.PPTX_2010);
    }
}
```
![Reorder Slide](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s5na6hs1adnnnwb2128h.jpg)