Remove Slide from Presentation
If a slide (or its contents) becomes redundant, you can delete it. Aspose.Slides provides the Presentation class that encapsulates SlideCollection, which is a repository for all slides in a presentation. Using pointers (reference or index) for a known Slide object, you can specify the slide you want to remove.
Remove Slide by Reference
- Create an instance of the Presentation class.
- Get a reference of the slide you want to remove through its ID or Index.
- Remove the referenced slide from the presentation.
- Save the modified presentation.
This JavaScript code shows you how to remove a slide through its reference:
// Instantiate a Presentation object that represents a presentation file
var pres = new aspose.slides.Presentation("demo.pptx");
try {
// Accesses a slide through its index in the slides collection
var slide = pres.getSlides().get_Item(0);
// Removes a slide through its reference
pres.getSlides().remove(slide);
// Saves the modified presentation
pres.save("modified.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
pres.dispose();
}
Remove Slide by Index
- Create an instance of the Presentation class.
- Remove the slide from the presentation through its index position.
- Save the modified presentation.
This JavaScript code shows you how to remove a slide through its index:
// Instantiates a Presentation object that represents a presentation file
var pres = new aspose.slides.Presentation("demo.pptx");
try {
// Removes a slide through its slide index
pres.getSlides().removeAt(0);
// Saves the modified presentation
pres.save("modified.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
pres.dispose();
}
Remove Unused Layout Slide
Aspose.Slides provides the removeUnusedLayoutSlides method (from the Compress class) to allow you to delete unwanted and unused layout slides. This JavaScript code shows you how to remove a layout slide from a PowerPoint presentation:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
aspose.slides.Compress.removeUnusedLayoutSlides(pres);
pres.save("pres-out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}
Remove Unused Master Slide
Aspose.Slides provides the removeUnusedMasterSlides method (from the Compress class) to allow you to delete unwanted and unused master slides. This JavaScript code shows you how to remove a master slide from a PowerPoint presentation:
var pres = new aspose.slides.Presentation("pres.pptx");
try {
aspose.slides.Compress.removeUnusedMasterSlides(pres);
pres.save("pres-out.pptx", aspose.slides.SaveFormat.Pptx);
} finally {
if (pres != null) {
pres.dispose();
}
}