Merge PowerPoint files in Python

While working with PowerPoint automation in Python, you may need to merge the content of multiple presentations. This could be required when a presentation is created by multiple people in parts that need to be merged eventually. To automate this merging, this article shows how to merge PowerPoint PPT or PPTX programmatically in Python.

Python Library to Merge PowerPoint PPTX

Aspose.Slides for Python via .NET is a powerful Python library for creating and manipulating presentation files. Moreover, it provides flexible ways to merge multiple PPT/PPTX presentations. We will utilize this library to merge presentations in this article. You can install it from PyPI using the following pip command.

> pip install aspose.slides

Merge PowerPoint PPT in Python

To merge the PPT presentations, you will need to clone the slides from one presentation to the other. The following are the steps to merge two PPT files in Python.

  • Create an object of Presentation class to load the first presentation.
  • Create another Presentation object to load the second presentation.
  • Start a loop to iterate through the slides in the second presentation.
  • In each iteration, merge the slide to first presentation using Presentation.slides.add_clone(ISlide) method.
  • Finally, save the merged presentation using Presentation.save(String, SaveFormat) method.

The following code sample shows how to merge two PowerPoint PPTX presentations in Python.

First Presentation

target powerpoint presentation

Second Presentation

source powerpoint presentation to be merged

Merged PPT

merged  powerpoint ppt in python

Python: Merge PPT Presentations with Different Slide Sizes

It is possible that the presentations you are going to merge use different sizes for their slides. In such cases, it is better to synchronize the size of the slides before merging. Let’s see how to merge PowerPoint PPT files having different slide sizes.

  • Create an object of Presentation class to load the first PPT.
  • Create another Presentation object to load the second PPT.
  • Change size of slides in second PPT using Presentation.slide_size.set_size(int, int, SlideSizeScaleType) method.
  • Start a loop to iterate through the slides in the second PPT.
  • In each iteration, merge the slide to first PPT using Presentation.slides.add_clone(ISlide) method.
  • Finally, save the merged PPT using Presentation.save(String, SaveFormat) method.

The following code sample shows how to merge PPT presentations having different slide sizes.

Merge PPT Slides to a Specific Section in Python

You can also merge PPT slides to a specific section of the target presentation. For this, Presentation.slides.add_clone(ISlide, ISection) method is used. The following code sample shows how to merge slides from the first presentation to a particular section of the second presentation.

Use Slide Master while Merging PowerPoint PPT

In the previous sections, we have merged the slides keeping the design and template of the second PPT. However, we may need to use the layout of the first (or destination) presentation for the cloned slides. In such cases, the overloaded method Presentation.slides.add_clone(ISlide, Presentation.masters[int], allow_clone_missing_layout = True) is used where second parameter defines the slide master.

The following code sample shows how to merge PPT presentations using desired slide master in Python.

Merged Presentation

combined powerpoint ppt in python

Python Library to Merge PowerPoint PPT - Get a Free License

You can get a free temporary license to merge PowerPoint presentations in Python without evaluation limitations.

Conclusion

In this article, you have learned how to merge PowerPoint PPT or PPTX presentations in Python. We have covered various scenarios of merging multiple PowerPoint presentations with the help of code samples. You can simply install the library and use the provided code samples in your applications. In case you want to explore more about Aspose.Slides for Python, you can visit the documentation. Also, you can ask your questions via our forum.

See Also

Info: Aspose free online PowerPoint Merger is a live implementation of the presentation merging process as a service.