Split Presentations

This demo uses the DevExpress Presentation API to extract presentation slides as separate files.

You can split the predefined sample file or supply your own document. To do the latter, select Upload a File in the file selection drop-down menu. In the Split Settings panel, select the presentation split mode and slides you want to extract.

Use the Extract and Save as... dropdown button to select the output format, extract slides, and download the result.

Sample document
Sample.pptx



using DevExpress.Docs.Presentation;

IReadOnlyList<Stream> ExtractSlides(Stream inputStream, List<int> slideIndexes, bool isSingleFileOutput,
    bool isPdfOutput, DocumentFormat documentFormat) {
    using var presentation = new Presentation(inputStream);
    return isSingleFileOutput
        ? ExtractSlidesSingleFile(slideIndexes, isPdfOutput, documentFormat, presentation)
        : ExtractSlidesDifferentFiles(slideIndexes, isPdfOutput, documentFormat, presentation);
}

IReadOnlyList<Stream> ExtractSlidesDifferentFiles(List<int> slideIndexes, bool isPdfOutput, DocumentFormat documentFormat, Presentation presentation) {
    var outputStreams = new List<Stream>();

    foreach(var slideIndex in slideIndexes) {
        if(slideIndex < 0 || slideIndex >= presentation.Slides.Count)
            continue;
        using var singleSlidePresentation = new Presentation();
        singleSlidePresentation.Slides.Clear();
        singleSlidePresentation.SlideSize = presentation.SlideSize;
        singleSlidePresentation.Slides.Add(presentation.Slides[slideIndex]);

        var outputStream = new MemoryStream();

        if(isPdfOutput)
            singleSlidePresentation.ExportToPdf(outputStream);
        else
            singleSlidePresentation.SaveDocument(outputStream, documentFormat);

        outputStream.Position = 0;
        outputStreams.Add(outputStream);
    }
    return outputStreams.AsReadOnly();
}
IReadOnlyList<Stream> ExtractSlidesSingleFile(List<int> slideIndexes, bool isPdfOutput, DocumentFormat documentFormat, Presentation presentation) {
    var outputStreams = new List<Stream>();

    for(int i = presentation.Slides.Count - 1; i >= 0; i--) {
        if(!slideIndexes.Contains(i))
            presentation.Slides.RemoveAt(i);
    }

    var outputStream = new MemoryStream();

    if(isPdfOutput)
        presentation.ExportToPdf(outputStream);
    else
        presentation.SaveDocument(outputStream, documentFormat);

    outputStream.Position = 0;
    outputStreams.Add(outputStream);
    return outputStreams.AsReadOnly();
}