Remove Slide from Presentation
Sometimes, developers may need to remove a slide from the presentation due to any reason. Aspose.Slides for C++ offers few methods to do so. In this topic, we will explore these methods to accomplish this task. We know that Presentation class in Aspose.Slides for C++ 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
Remove Slide by Reference
To remove a slide using its reference, please follow the steps below:
- Create an instance of
Presentation
class. - Obtain the reference of a slide by using its Id or Index.
- Remove the referenced slide from the presentation.
- Write the modified presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = L"../templates/AddSlides.pptx"; | |
const String outPath = L"../out/RemoveSlidesByReference.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Accessing Slide by ID from collection | |
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0); | |
// Removing a slide using its reference | |
pres->get_Slides()->Remove(slide); | |
// Writing the presentation file | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |
Remove Slide by Index
To remove a slide using its index position in the slides collection of the presentation, please follow the steps below:
- Create an instance of
Presentation
class. - Remove the slide from the presentation by using its index position.
- Write the modified presentation file.
For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C | |
// The path to the documents directory. | |
const String templatePath = L"../templates/AddSlides.pptx"; | |
const String outPath = L"../out/RemoveSlidesByID.pptx"; | |
// Instantiate Presentation class | |
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath); | |
// Removing a slide using its slide index | |
pres->get_Slides()->RemoveAt(0); | |
// Writing the presentation file | |
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx); | |