Working with multiple PowerPoint presentations at the same time can be a daunting task, often resulting in a less-than-ideal presentation experience. However, there is a solution that can streamline this process and ensure seamless transitions throughout the presentation. By combining multiple PowerPoint files into a single cohesive presentation, presenters can eliminate the need to repeatedly open different files, saving time and effort. While manually copying slides can be arduous and time-consuming, Python offers a swift and efficient solution. This article is going to show how to leverage Spire.Presentation for Python to merge PowerPoint presentations effortlessly through Python programs.
- Merging PowerPoint Presentations and Retain Their Designs
- Merging PowerPoint Presentations with Consistent Design
Install Spire.PDF for Python
This scenario requires Spire.Presentation for Python and plum-dispatch v1.7.4. They can be easily installed in your Windows through the following pip command.
pip install Spire.Presentation
If you are unsure how to install, please refer to: How to Install Spire.Presentation for Python on Windows
Merging PowerPoint Presentations and Retain Their Designs
Merging PowerPoint presentations can be accomplished by reading slides from one presentation and adding them to another presentation. During the process of adding to the target presentation, developers can use Presentation.Slides.AppendBySlide(ISlide) method to add slides and retain the original design of the slides.
The detailed steps are as follows:
- Create two instances of Presentation class.
- Load two PowerPoint presentations using Presentation.LoadFromFile() method.
- Iterate through each slide in the second presentation and add them to the first presentation while keeping their design using Presentation.Slides.AppendBySlide() method.
- Save the first presentation using Presentation.SaveToFile() method.
- Python
from spire.presentation import * from spire.presentation.common import * # Create two instances of Presentation class pres1 = Presentation() pres2 = Presentation() # Load two presentation files pres1.LoadFromFile("Sample1.pptx") pres2.LoadFromFile("Sample2.pptx") # Iterate through the slides of the second presentation for slide in pres2.Slides: # Add each slides to the first presentation and keep the original design pres1.Slides.AppendBySlide(slide) # Save the first presentation pres1.SaveToFile("output/MergePresentations.pptx", FileFormat.Pptx2016) pres1.Dispose() pres2.Dispose()
Merging PowerPoint Presentations with Consistent Design
Developers can also use Presentation.Slides.AppendByMaster(slide Islide, master IMasterSlide) method to insert slides into the target presentation and change the design of the slides to the design of the target presentation. This allows for merging presentations and ensuring a consistent design.
The detailed stops are as follows:
- Create two instances of Presentation class.
- Load two PowerPoint presentations using Presentation.LoadFromFile() method.
- Iterate through each slide in the second presentation and add them to the first presentation while changing their design to the design of the first presentation using Presentation.Slides.AppendByMaster() method.
- Save the first presentation using Presentation.SaveToFile() method.
- Python
from spire.presentation import * from spire.presentation.common import * # Create two instances of Presentation class pres1 = Presentation() pres2 = Presentation() # Load two presentation files pres1.LoadFromFile("Sample1.pptx") pres2.LoadFromFile("Sample2.pptx") # Iterate through each slide in the second presentation for slide in pres2.Slides: # Add each slide to the first presentation pres1.Slides.AppendByMaster(slide, pres1.Masters[0]) # Save the first presentation pres1.SaveToFile("output/MergePresentationsDesign.pptx", FileFormat.Pptx2016) pres1.Dispose() pres2.Dispose()
Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.