PowerPoint presentations are used in many scenarios such as meetings, presentations, discussions, etc. There might be situations where you have different presentations created by separate people or have individual presentations used in various meetings. You might need to merge these presentations for sharing or documentation purposes. Doing this task manually would be time-consuming. The efficient way would be to achieve this programmatically. In this article, you will learn how to merge PowerPoint presentations using C++.
- C++ API to Merge PowerPoint Presentations
- Merge PowerPoint Presentations using C++
- Merge Specific PowerPoint Slides using C++
- Use Slide Master to Merge PowerPoint Presentations
- Get a Free License
C++ API to Merge PowerPoint Presentations
Aspose.Slides for C++ is a C++ library that provides a bunch of features for working with PowerPoint presentations. The API allows you to create, modify and convert PowerPoint presentations without using Microsoft PowerPoint. Furthermore, the API provides the ability to merge different PowerPoint files. You can either install the API through NuGet or download it directly from the Downloads section.
PM> Install-Package Aspose.Slides.Cpp
Merge PowerPoint Presentations using C++
The process for merging two presentations using Aspose.Slides for C++ is a breeze. To achieve this, you load both the presentations, loop through the source presentation slides, and add their clone to the target presentation. The following are the steps to merge two PowerPoint presentations.
- Load the destination PowerPoint file using the Presentation class.
- Create another instance of the Presentation class to represent the source PowerPoint file.
- Retrieve the slides from the source presentation using the Presentation->get_Slides() method and iterate over them.
- Inside the loop, add each slide to the destination presentation using the Presentation->get_Slides()->AddClone (System::SharedPtr<ISlide> sourceSlide) method.
- Finally, save the merged presentation file using the Presentation->Save (System::String name, Export::SaveFormat format) method.
The following is the sample code to merge PowerPoint presentations using C++.
The following images show the source, destination and merged presentation files.
Destination Presentation
Source Presentation
Merged Presentation
Merge Specific PowerPoint Slides using C++
There might be situations where you are not interested in the whole presentation but instead, want to add a subset of slides. To achieve this, you add the necessary condition while looping through the source presentation slides. The following are the steps to merge selected PowerPoint slides.
- Firstly, load the destination PowerPoint file using the Presentation class.
- Create another instance of the Presentation class to represent the source PowerPoint file.
- Retrieve the slides from the source presentation using the Presentation->get_Slides() method and iterate over them.
- Inside the loop, add the required slides to the destination presentation using the Presentation->get_Slides()->AddClone (System::SharedPtr<ISlide> sourceSlide) method.
- Finally, save the merged presentation file using the Presentation->Save (System::String name, Export::SaveFormat format) method.
The following is the sample code to merge selected PowerPoint slides using C++.
The following image shows the merged presentation file. The source and the destination presentation files are the same as used in the previous example.
Merged Presentation
Use Slide Master to Merge PowerPoint Presentations
In the previous two examples, the design of both the source and destination presentations was the same. The following images show the result of merging presentations with different designs.
Destination Presentation
Source Presentation
Merged Presentation
You can see in the merged presentation image that the third slide retained its original styling during the merge process. If you want the source slides to use the destination presentation styles, please use the following steps.
- Load the destination PowerPoint file using the Presentation class.
- Create another instance of the Presentation class to represent the source PowerPoint file.
- Add the required slides to the destination presentation using the Presentation->get_Slides()->AddClone (System::SharedPtr<ISlide> sourceSlide, System::SharedPtr<IMasterSlide> destMaster, bool allowCloneMissingLayout) method.
- Finally, save the merged presentation file using the Presentation->Save (System::String name, Export::SaveFormat format) method.
The following is the sample code to merge PowerPoint presentations using slide master.
The following image shows the merged presentation generated by the above sample code.
Merged Presentation
Get a Free License
You can try the API without evaluation limitations by requesting a free temporary license.
Conclusion
In this article, you have learned how to merge multiple PowerPoint presentations using C++. You have seen how to merge complete presentations or selected slides. Furthermore, you have learned how to use the style of the destination presentation for combining the presentations. Aspose.Slides for C++ offers many additional features for working with PowerPoint files. You can explore the API in detail by using the official documentation. If you have any questions, please feel free to contact us on the forum.