Skip to main content
All docs
V25.1
  • DevExpress Presentation API Library: Manage Slides

    • 4 minutes to read

    Important

    The DevExpress Presentation API Library is currently available as a Community Technology Preview (CTP). Note that we do not recommend that you integrate pre-release libraries into mission-critical software applications. You can try the library and share your feedback so that we can make necessary adjustments before the official release. To start a conversation, submit a ticket via the DevExpress Support Center — we’d love to hear from you.

    The DevExpress Presentation API library allows you to perform various tasks with slides: add new slides to a presentation, modify existing slides, duplicate and merge slides, and much more.

    To get more information on how to create or load presentations, refer to the following help topic: DevExpress Presentation API Library: Create, Load, and Save Presentations.

    Access Presentation Slides

    Use the Presentation.Slides property to access the collection of slides within the presentation.

    using DevExpress.Docs.Presentation;
    
        // Load a presentation from a local PPTX file:
        Presentation presentation = new Presentation(File.ReadAllBytes(@"D:\testpresentation.pptx"));
    
        // Access the first slide in the presentation:
        var slide = presentation.Slides[0]
    

    Add a Slide

    Follow the steps below to add a slide to the presentation’s Slides collection:

    • Create a Slide object. Specify a layout type in the constructor.
    • Call the Add or Insert method to add the newly created slide to the presentation.
    using DevExpress.Docs.Presentation;
    
        Presentation presentation = new Presentation();
        Slide slide = new Slide(new SlideLayout(layoutType: SlideLayoutType.Blank, name: "slide"));
        presentation.Slides.Add(slide);
    

    Create and Add a Slide Based on a Slide Master

    The Slide Master is a template slide that you can use as a base for other slides. Presentation API distributes slide master content — such as shapes, layouts, and text styles — across all slides created from it. Changes made to the slide master are immediately applied to all its descendant slides.

    Slide masters contain layout presets used to organize content placeholders on a slide. Call the slide master’s Layouts.Get method to obtain a layout of the specified type. You can also call the Layouts.GetOrCreate method to obtain a layout. If the requested layout does not exist, it is automatically created.

    using DevExpress.Docs.Presentation;
    
        Slide slide = new Slide(presentation.SlideMasters[0].Layouts.Get(SlideLayoutType.Title));
        presentation.Slides.Add(slide);
    

    For more information about slide masters, refer to the following help topic: DevExpress Presentation API Library: Configure Slide Masters and Layouts.

    Manage Slide Visibility

    The Visible property indicates whether the slide is visible.

    The following code snippet removes invisible slides from the presentation:

    foreach (Slide slide in presentation.Slides) {
        if (!slide.Visible) {
            presentation.Slides.Remove(slide);
        }
    }
    

    Duplicate Slides

    Call a slide’s Clone method to create this slide’s copy. Then you can use this copy as a base for another slide:

    Slide clonedSlide = slide.Clone();
    presentation.Slides.Add(clonedSlide);
    

    Reorder Slides

    Call the SlideCollection.Move method to rearrange slides within the Presentation.Slides collection.

    presentation.Slides.Move(slide, 1);
    presentation.Slides.Move(3, 2);
    

    Copy Slides from Another Presentation

    The following code snippet adds slides to a presentation from another presentation to merge two presentations:

    Presentation presentation1 = new Presentation(File.ReadAllBytes(@"presentation1.pptx"));
    Presentation presentation2 = new Presentation(File.ReadAllBytes(@"presentation2.pptx"));
    foreach (Slide slide in presentation2.Slides) { 
        presentation1.Slides.Add(slide);
    }
    

    For more examples on how to merge and split presentations, refer to the following help topic: Merge and Split Presentations with the DevExpress Presentation API Library.

    Remove Slides

    Call the following methods to remove a slide from the presentation:

    • Remove - Removes the given slide object.
    • RemoveAt - Removes the slide with the given index.
    • Clear - Removes all slides from the collection.
    presentation.Slides.Remove(slide);
    presentation.Slides.RemoveAt(0);
    presentation.Slides.Clear();