# Remove Slides from Presentations in C++

> Effortlessly remove slides from PowerPoint and OpenDocument presentations with Aspose.Slides for C++. Get clear code examples and boost your workflow.

Source: https://docs.aspose.com/slides/cpp/remove-slide-from-presentation/
Updated: 2026-08-05


## **Introduction**

If a slide (or its contents) becomes redundant, you can delete it. Aspose.Slides provides the [Presentation](https://reference.aspose.com/slides/cpp/aspose.slides/presentation/) class that encapsulates [ISlideCollection](https://reference.aspose.com/slides/cpp/aspose.slides/islidecollection/), which is a repository for all slides in a presentation. Using pointers (reference or index) for a known [ISlide](https://reference.aspose.com/slides/cpp/aspose.slides/islide/) object, you can specify the slide you want to remove. 

## **Remove a Slide by Reference**

1. Create an instance of the [Presentation](https://reference.aspose.com/slides/cpp/aspose.slides/presentation/) class.
1. Get a reference of the slide you want to remove through its ID or Index.
1. Remove the referenced slide from the presentation.
1. Save the modified presentation. 

This C++ code shows you how to remove a slide through its reference: 

```c++
#include <DOM/ISlide.h>
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;

// The path to the documents directory
const String templatePath = u"../templates/AddSlides.pptx";
const String outPath = u"../out/RemoveSlidesByReference.pptx";

// Instantiates a Presentation object that represents a presentation file
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);

// Accesses a slide through its index in the slides collection
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);

// Removes a slide through its reference
pres->get_Slides()->Remove(slide);

// Saves the modified presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
```


## **Remove a Slide by Index**

1. Create an instance of the [Presentation](https://reference.aspose.com/slides/cpp/aspose.slides/presentation/) class.
1. Remove the slide from the presentation through its index position.
1. Save the modified presentation. 

This C++ code shows you how to remove a slide through its index: 

```c++
#include <DOM/ISlideCollection.h>
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <system/string.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace System;

// The path to the documents directory
const String templatePath = u"../templates/AddSlides.pptx";
const String outPath = u"../out/RemoveSlidesByID.pptx";

// Instantiates a Presentation object that represents a presentation file
SharedPtr<Presentation> pres = MakeObject<Presentation>(templatePath);

// Removes a slide through its slide index
pres->get_Slides()->RemoveAt(0);

// Saves the modified presentation
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);
```

## **Remove Unused Layout Slides**

Aspose.Slides provides the [RemoveUnusedLayoutSlides()](https://reference.aspose.com/slides/cpp/aspose.slides.lowcode/compress/removeunusedlayoutslides/) method (from the [Compress](https://reference.aspose.com/slides/cpp/aspose.slides.lowcode/compress/) class) to allow you to delete unwanted and unused layout slides. This C++ code shows you how to remove a layout slide from a PowerPoint presentation:

```c++
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <LowCode/Compress.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::LowCode;

auto pres = System::MakeObject<Presentation>(u"pres.pptx");

LowCode::Compress::RemoveUnusedLayoutSlides(pres);

pres->Save(u"pres-out.pptx", SaveFormat::Pptx);
```

## **Remove Unused Master Slides**

Aspose.Slides provides the [RemoveUnusedMasterSlides()](https://reference.aspose.com/slides/cpp/aspose.slides.lowcode/compress/removeunusedmasterslides/) method (from the [Compress](https://reference.aspose.com/slides/cpp/aspose.slides.lowcode/compress/) class) to allow you to delete unwanted and unused master slides. This C++ code shows you how to remove a master slide from a PowerPoint presentation:

```c++
#include <DOM/Presentation.h>
#include <Export/SaveFormat.h>
#include <LowCode/Compress.h>
using namespace Aspose::Slides;
using namespace Aspose::Slides::Export;
using namespace Aspose::Slides::LowCode;

auto pres = System::MakeObject<Presentation>(u"pres.pptx");

LowCode::Compress::RemoveUnusedMasterSlides(pres);

pres->Save(u"pres-out.pptx", SaveFormat::Pptx);
```

## **FAQ**

### What happens to slide indexes after I delete a slide?

After deletion, the [collection](https://reference.aspose.com/slides/cpp/aspose.slides/slidecollection/) reindexes: every subsequent slide shifts left by one position, so previous index numbers become outdated. If you need a stable reference, use each slide’s persistent ID rather than its index.

### Is a slide’s ID different from its index, and does it change when neighboring slides are deleted?

Yes. The index is the slide’s position and will change when slides are added or removed. The slide ID is a persistent identifier and does not change when other slides are deleted.

### How does deleting a slide affect slide sections?

If the slide belonged to a section, that section will simply contain one fewer slide. The section structure remains; if a section becomes empty, you can [remove or reorganize sections](/slides/cpp/slide-section/) as needed.

### What happens to notes and comments attached to a slide when it’s deleted?

[Notes](/slides/cpp/presentation-notes/) and [comments](/slides/cpp/presentation-comments/) are tied to that specific slide and are removed along with it. Content on other slides is unaffected.

### How is deleting slides different from cleaning up unused layouts/masters?

Deleting removes specific normal slides from the deck. Cleaning up unused layouts/masters removes layout or master slides that nothing references, reducing file size without changing remaining slide content. These actions are complementary: typically delete first, then clean up.

