Skip to main content
All docs
V26.1
  • Merge and Split Presentations with the DevExpress Presentation API Library

    • 4 minutes to read

    This topic contains examples that implement the following merge and split tasks:

    • Reuse slides in multiple presentations
    • Combine multiple presentations into one presentation
    • Split presentations

    Notes on Presentation Merge Operations

    • When you merge presentations, the target presentation determines the slide size. If you merge a slide into a presentation with a smaller slide size, some shapes may fall outside the visible area. These shapes remain in the presentation and retain their original coordinates. Use the Presentation.ResizeSlides method to resize the slides and scale their content to the target presentation’s slide size.
    • Merged slides keep their original formatting and style settings.
    • Slide masters used by source presentation slides are automatically transferred to the target presentation (along with their theme and all their layouts).

    Copy a Slide from Another Presentation

    The following code snippet extracts a slide from a presentation and inserts it into another presentation:

    using DevExpress.Docs.Presentation;
    
    namespace PptxSample;
    
    public class Program {
        public static void Main(string[] _) {
    
            // Load the first presentation from a file
            Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\my-presentation.pptx"));
    
            // Load the second presentation from a file
            Presentation presentation2 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
    
            // Clone the first slide from the first presentation, so you can edit the copy not the original slide, if necessary
            Slide slide1 = presentation1.Slides[0].Clone();
    
            // Insert the cloned slide at the beginning of the second presentation
            presentation2.Slides.Insert(0, slide1);
    
            // Export the modified second presentation to a PDF file
            presentation2.ExportToPdf(new FileStream(@"D:\exported-document.pdf", FileMode.Create));
        }
    }
    

    Merge Multiple Presentations

    Run Demo: Merge Presentations

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

    using DevExpress.Docs.Presentation;
    
    namespace PptxSample;
    
    public class Program {
        public static void Main(string[] _) {
    
            // Load the first presentation from a file
            Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\my-presentation.pptx"));
    
            // Load the second presentation from a file
            Presentation presentation2 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
    
            // Append all slides from the second presentation to the first presentation
            foreach (Slide slide in presentation2.Slides) {
                presentation1.Slides.Add(slide);
            }
    
            // Export the resulting presentation to PDF
            presentation1.ExportToPdf(new FileStream(@"D:\exported-document.pdf", FileMode.Create));
        }
    }
    

    Split a Presentation

    Run Demo: Split Presentation

    The following code snippet extracts slides from a presentation and puts them into an empty presentation:

    using DevExpress.Docs.Presentation;
    
    namespace PptxSample;
    
    public class Program {
        public static void Main(string[] _) {
    
            // Load the Northwind presentation from a file
            Presentation presentation1 = new Presentation(File.ReadAllBytes(@"..\..\..\data\NorthwindPresentation.pptx"));
    
            // Create a new empty presentation
            Presentation presentation2 = new Presentation();
    
            // Remove default slides in presentation 
            presentation2.Slides.Clear();
    
            // Set the presentation2 slide size to match presentation1
            presentation2.SlideSize = presentation1.SlideSize;
    
            // Move the first three slides from presentation1 to presentation2
            for (int i = 0; i < 3; i++)
            {
                presentation2.Slides.Add(presentation1.Slides[0]);
                presentation1.Slides.RemoveAt(0);
            }
    
            // Export the modified presentation1 (with the remaining slides) to PDF
            presentation1.ExportToPdf(new FileStream(@"D:\exported-document1.pdf", FileMode.Create));
            // Export presentation2 (with the first three slides) to PDF
            presentation2.ExportToPdf(new FileStream(@"D:\exported-document2.pdf", FileMode.Create));
        }
    }