Delete Slides from Presentation using Apache POI and Aspose.Slides
Contents
[
Hide
]
Aspose.Slides - Delete Slides from Presentation
Sometimes, developers may need to remove a slide from the presentation due to any reason. Aspose.Slides for Java offers few methods to do so.
We know that Presentation class in Aspose.Slides for Java represents a presentation file. Presentation class encapsulates a ISlideCollection that acts as a repository of all slides that are the part of the presentation. Developers can remove a slide from this Slides collection in two ways:
- Using Slide Reference
- Using Slide Index
//Instantiate a PresentationEx object that represents a PPTX file
Presentation pres = new Presentation("presentation.pptx");
pres.getSlides().removeAt(1); //Removing a slide using its index
//Accessing a slide using its index in the slides collection
ISlide slide = pres.getSlides().get_Item(0);
pres.getSlides().remove(slide); //Removing a slide using its reference
Apache POI SL - HSLF XSLF - Delete Slides from Presentation
Slides can be deleted by calling removeSlide from the presentation and passing the index of the slide to be deleted while using Apache POI SL.
XMLSlideShow ppt = new XMLSlideShow(new FileInputStream("presentation.pptx"));
ppt.removeSlide(0); // 0-based index of a slide to be removed
Download Running Code
Download Sample Code
For more details, visit Removing Slides from a Presentation.