Operate the presentation slide on Java applications

This article will demonstrate how to use Spire.Presentaion for Java to operate the presentation slides. Such as adding new slide in PowerPoint document, removing an existing slide, hiding slide from a PowerPoint document and changing the Slide Order within a Presentation in Java applications.

Add new slides to an existing PowerPoint document.

import com.spire.presentation.*;

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

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.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);
    }

}

Operate the presentation slide on Java applications

Hide a slide that we don't want to present to audiences without deleting it.

import com.spire.presentation.*;
public class Slides {
    public static void main(String[] args) throws Exception {
        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");
        
        //Hide the second slide
        presentation.getSlides().get(1).setHidden(true);

        //Save the document
        presentation.saveToFile("output/HideSlide.pptx", FileFormat.PPTX_2010);
    }
}

Operate the presentation slide on Java applications

Delete a slide from the PowerPoint document

import com.spire.presentation.*;
public class Slides {
    public static void main(String[] args) throws Exception {
        
        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.pptx");
        
        //Remove the third slide
        presentation.getSlides().removeAt(2);
      
        //Save the document
        presentation.saveToFile("output/Removeslide.pptx", FileFormat.PPTX_2010);
    }
}

Operate the presentation slide on Java applications

Change the Slide Order within a PowerPoint document

import com.spire.presentation.*;

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

        //Create a PPT document and load file
        Presentation presentation = new Presentation();
        presentation.loadFromFile("C:\\Users\\Administrator\\Desktop\\Sample.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);
    }

}

Operate the presentation slide on Java applications