Merging PowerPoint presentations can be useful in various scenarios such as combining content from multiple PPT/PPTX, merging parts of a single presentation created by two or more people, and etc. The manual way of copying/pasting the content may not be suitable when dealing with a number of presentations. Therefore, this article lets the .NET developers learn how to merge PowerPoint presentations programmatically using C#.
TIP: You may be interested in trying out a web viewer app for presentations developed with Aspose’s APIs.
- .NET PowerPoint Merger API
- Merge PowerPoint Presentations using C#
- Merge Particular Slides of PowerPoint Presentations using C#
- Use Slide Master while Merging PowerPoint Presentations
.NET PowerPoint Merger API
Aspose.Slides for .NET is a feature-rich .NET PowerPoint API that lets you create and manipulate presentation documents. Along with that, it allows you to combine two or more PowerPoint presentations using C# or VB.NET. You can download the API’s DLL or install it using NuGet.
Merge PowerPoint Presentations using C#
In this section, you will learn how to clone and merge all the slides from one PowerPoint presentation to another. For this, you can simply clone the slides from the source presentation and add them at the end of the target presentation. The following are the steps to merge two presentations.
- Create an object of Presentation class to load the target presentation file.
- Create another Presentation object to load the source presentation from where you’ll clone the slides.
- Access the collection of slides from source presentation using Presentation.Slides property.
- Loop through the slides collection and merge them into the target presentation using Presentation.Slides.AddClone(ISlide) method.
- Save the merged presentation using Presentation.Save(String, SaveFormat) method.
The following code sample shows how to merge two PowerPoint presentations using C#.
Merge Particular Slides of PowerPoint Presentations using C#
In the previous example, you have merged all the slides from the source PPTX file into the target PPTX. However, there might be the case when you need to merge only the selected slides. In such a case, you can specify the slides to be merged using the slide’s index. The following are the steps to perform this operation.
- Load the target presentation using the Presentation class.
- Load the source presentation using the Presentation class.
- Clone the desired slides using presentation1.Slides.AddClone(presentation2.Slides[int Index]) method.
- Save the merged presentation as a new PPTX file.
The following code sample shows how to merge particular slides of presentations using C#.
Use Slide Master while Merging PowerPoint Presentations
In both of the previous examples, you have merged the slides keeping the design and template of the source presentation. However, in certain cases, you may need to modify the layout of the slides in accordance with the target presentation. In such cases, you can use the overloaded presentation1.Slides.AddClone(presentation2.Slides, presentation1.Masters, true) method.
The following code sample shows how to merge the slides in PowerPoint presentation using the Slide Master in C#.
In this article, you have learned how to merge two or multiple PowerPoint presentations using C#. You can port the C# code samples in order to merge presentations using VB.NET. In case you want to explore more about Aspose’s .NET PowerPoint API, you can visit the documentation.