How can I combine two presentations (pptx) into one master presentation?

5.5k views Asked by At

I'm part of a project team that created PPTX presentations to present to clients. After creating all of the files, we need to add additional slides to each presentation. All of the new slides will be the same across the each presentation.

What is the best way to accomplish this programmatically?

I don't want to use VBA because (as far as I understand) I would have to open each presentation to run the script.

I've tried using the python-pptx library. But the documentation states:

"Copying a slide from one presentation to another turns out to be pretty hard to get right in the general case, so that probably won’t come until more of the backlog is burned down."

I was hoping something like the following would work -

from pptx import Presentation

main = Presentation('Universal.pptx')
abc = Presentation('Test1.pptx')

main_slides = main.slides.get(1)
abc_slides = abc.slides.get(1)

full = main.slides.add_slide(abc_slides[1])

full.save('Full.pptx')

Has anyone had success do anything like that?

3

There are 3 answers

0
Tilal Ahmad On

The GroupDocs.Merger REST API is also another option to merge multiple PowerPoint presentations into a single document. It is paid API but provides 150 monthly free API calls.

Currently, it supports working with cloud providers: Amazon S3, DropBox, Google Drive Storage, Google Cloud Storage, Windows Azure Storage, FTP Storage along with GroupDocs internal Cloud Storage. However, in near future, it has a plan to support merge files from the request body(stream).

P.S: I'm developer evangelist at GroupDocs.

# For complete examples and data files, please go to https://github.com/groupdocs-merger-cloud/groupdocs-merger-cloud-python-samples
# Get Client ID and Client Secret from https://dashboard.groupdocs.cloud
client_id = "XXXX-XXXX-XXXX-XXXX" 
client_secret = "XXXXXXXXXXXXXXXX"
  
documentApi = groupdocs_merger_cloud.DocumentApi.from_keys(client_id, client_secret)
 
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("four-slides.pptx")
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("one-slide.docx")
 
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "Output/joined.pptx"
 
result = documentApi.join(groupdocs_merger_cloud.JoinRequest(options))
5
Zeynel On

I was able to achieve this by using python and win32com.client. However, this doesn't work quietly. What I mean is that it launches Microsoft PowerPoint and opens input files one by one, then copies all slides from an input file and pastes them to an output file in a loop.

import win32com.client
from os import walk

def mergePresentations(inputFileNames, outputFileName):

    Application = win32com.client.Dispatch("PowerPoint.Application")
    outputPresentation = Application.Presentations.Add() 
    outputPresentation.SaveAs(outputFileName)

    for file in inputFileNames:    
        currentPresentation = Application.Presentations.Open(file)
        currentPresentation.Slides.Range(range(1, currentPresentation.Slides.Count+1)).copy()
        Application.Presentations(outputFileName).Windows(1).Activate()    
        outputPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting")    
        currentPresentation.Close()

    outputPresentation.save()
    outputPresentation.close()
    Application.Quit()

# Example; let's say you have a folder of presentations that need to be merged 
#           to new file named "allSildesMerged.pptx" in the same folder

path,_,files = next(walk('C:\\Users\\..\\..\\myFolder'))
outputFileName = path + '\\' + 'allSildesMerged.pptx'

inputFiles = []
for file in files:
    inputFiles.append(path + '\\' + file)

mergePresentations(inputFiles, outputFileName)

0
Statham On

A free tool called "powerpoint join" can help you.