---
title: "Extract PowerPoint slides to a new PPTX in C#"
url: https://recursiveai.org/onedocument/cookbook/extract-slides-into-new-powerpoint/
description: "Extract a range of PowerPoint slides to a new PPTX in C# with OneDocument. Select slides by start index and count, and keep the masters those slides use."
version: "1.0.0"
---

# Extract PowerPoint slides to a new PPTX in C#

**OneDocument** is a free, open-source Word, Excel and PowerPoint document library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneDocument.Presentations) · [GitHub](https://github.com/recursive-ai-oss/onedocument-csharp) · [Docs](https://recursiveai.org/onedocument/docs/) · [Download example (.zip)](https://recursiveai.org/onedocument/cookbook/extract-slides-into-new-powerpoint/extract-slides-into-new-powerpoint.zip)

Download includes `review.pptx`.

```shell
dotnet add package RecursiveAI.OneDocument.Presentations
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using RecursiveAI.OneDocument.Presentations;
using var deck =
    Presentation.Open("review.pptx");
using var excerpt = deck.ExtractSlides(1, 2);
excerpt.SaveAs("slides-2-3.pptx");
```

`ExtractSlides(start, count)` uses a zero-based start index and a slide count, so `(1, 2)` means slides 2–3.

Writes `slides-2-3.pptx` with Sales and Costs; prints nothing.

[The example](https://recursiveai.org/onedocument/cookbook/extract-slides-into-new-powerpoint/extract-slides-into-new-powerpoint.zip) is the full program below: unzip it and `dotnet run`. To run only the code above, paste it into Program.cs of a new `dotnet new console` project and `dotnet run`.

## The full program

In `review.pptx`, the slides are Agenda, Sales, Costs and Next steps. The full program opens the saved file and prints the slide count and text.

```csharp
using RecursiveAI.OneDocument.Presentations;

using var deck = Presentation.Open("review.pptx");
using var excerpt = deck.ExtractSlides(start: 1, count: 2);
excerpt.SaveAs("slides-2-3.pptx");

using var saved = Presentation.Open("slides-2-3.pptx");
Console.WriteLine($"Slides: {saved.Slides.Count}");
foreach (var slide in saved.Slides)
    foreach (var shape in slide.Shapes)
        if (!string.IsNullOrEmpty(shape.Text))
            Console.WriteLine(shape.Text);
```

```text
Slides: 2
Sales
Costs
```

An empty range or a range outside the presentation throws `ArgumentOutOfRangeException` before the example saves anything.

## Variations

**Split the whole deck into two-slide presentations.** If the deck has an odd number of slides, the last file has one slide.

```csharp
using RecursiveAI.OneDocument.Presentations;
using var deck = Presentation.Open("review.pptx");
var parts = deck.SplitEvery(2);
try
{
    for (int i = 0; i < parts.Count; i++)
        parts[i].SaveAs($"part-{i + 1}.pptx");
}
finally
{
    foreach (var part in parts)
        part.Dispose();
}
```

Writes `part-1.pptx` (Agenda and Sales) and `part-2.pptx` (Costs and Next steps).

## Related recipes

- [Merge PowerPoint presentations](https://recursiveai.org/onedocument/cookbook/merge-powerpoint-slides/)
- [Edit PowerPoint speaker notes](https://recursiveai.org/onedocument/cookbook/edit-powerpoint-speaker-notes/)

## The short answer

Call `ExtractSlides(start, count)` on the source presentation, then call `SaveAs` on the returned presentation. To save slides 2 through 3, pass `start: 1, count: 2`. Use a different filename to keep the original PPTX on disk.

## How do I extract multiple slides from PowerPoint?

Use one call for a contiguous range. If someone asks for slide numbers 4 through 7, the first index is `4 - 1` and the count is `7 - 4 + 1`. The second argument is a count, not the ending index. For one slide, pass `1` as the count. To break up the whole deck into regular batches rather than selecting one range, use `SplitEvery` as shown above.

`ExtractSlides` returns a separate presentation in memory and leaves the original slides in place. Dispose the returned presentation when you finish saving it. This method doesn’t select nonadjacent slides such as 2 and 5 in one call, and it doesn’t insert the extracted slides into an existing presentation.

## How do I copy PowerPoint slides without losing their formatting?

When the destination is a new PPTX, [slide extraction](https://recursiveai.org/onedocument/docs/operations-merge/) starts with a copy of the source deck. It deletes slides outside the requested range and prunes unused masters. A slide master is the shared design for a set of slide layouts. The new deck keeps the masters used by the selected slides, including those masters’ layouts. The extracted slides don’t have to switch to a layout from a new blank presentation.

The retained slides keep their speaker notes and the parts they use. Resources used only by the removed slides or unused masters can be removed. If the job is to add slides to a deck that already exists, use [`InsertSlides`](https://recursiveai.org/onedocument/cookbook/merge-powerpoint-slides/) instead; there you can choose between source and destination formatting.
