0
votes

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
"I don't want to use VBA because (as far as I understand) I would have to open each presentation to run the script." Each presentation would need to be opened in PPT in order for VBA to do any good, but the VBA in one presentation or add-in could automate the work of opening each presentation in a list or in a folder and doing whatever's needed, then saving and closing it before moving on to the next presentation.Steve Rindsberg
That's a really interesting idea. I'll have to take a look into that. Any way you could point me in the direction of a good source for inexperienced-friendly documentation? Thanks again!Brad Lide
There's a section on PowerPoint programming in the PPT FAQ site that I maintain here: pptfaq.com/index.html#name_PROGRAMMING_POWERPOINT Lots of examples and links to other sites on the subject. This entry might be useful for your project: pptfaq.com/…Steve Rindsberg
Better late than never, thanks so much for your guidance. We ended up grabbing a team to workhorse it manually, but I learned a lot using those resources and have them in my toolbelt for the future when a project may not be so time sensitive. Thanks again.Brad Lide

3 Answers

0
votes

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
votes

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))
-2
votes

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