Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save groupdocs-cloud-gists/d4edf45f40210be2357b1f4cf05f101d to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/d4edf45f40210be2357b1f4cf05f101d to your computer and use it in GitHub Desktop.
Combine and Merge PowerPoint PPT/PPTX Files in Python

You can combine PowerPoint files programmatically on the cloud. In this article, you will learn how to combine and merge multiple PPTX files in Python using REST API.

The following topics are covered in this article:

  1. Python PowerPoint Merger REST API - Installation
  2. Merge PowerPoint PPTX Files in Python using REST API
  3. Merge Specific Pages of Multiple PPTX Files in Python
# How to merge PowerPoint PPTX files in Python
# Create necessary API instances
documentApi = groupdocs_merger_cloud.DocumentApi.from_config(configuration)
# Input source file 1
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("python-testing/powerpoint-one.pptx")
# Input source file 2
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("python-testing/powerpoint-two.pptx")
# Define join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "python-testing/joined-files.pptx"
# Create join request
request = groupdocs_merger_cloud.JoinRequest(options)
# Merge pptx files
result = documentApi.join(request)
print("Successfully merged PPTX files: " + str(result))
# API initialization to download merged file
import shutil
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration)
# Create download file request
request = groupdocs_merger_cloud.DownloadFileRequest("python-testing\\joined-files.pptx", storage_name)
# Download merged file
response = file_api.download_file(request)
# Move the downloaded file to your directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# Upload PowerPoint files to cloud storage
# Create instance of the API
import glob
file_api = groupdocs_merger_cloud.FileApi.from_config(configuration)
storage_api = groupdocs_merger_cloud.StorageApi.from_config(configuration)
# upload sample files
for filename in glob.iglob("H:\\groupdocs-cloud-data\\upload\\*.pptx", recursive=True):
destFile = filename.replace("H:\\groupdocs-cloud-data\\upload", "", 1)
# check if file already exist
fileExistsResponse = storage_api.object_exists(groupdocs_merger_cloud.ObjectExistsRequest(destFile))
if not fileExistsResponse.exists:
# create upload file request
request = groupdocs_merger_cloud.UploadFileRequest(destFile, filename)
# upload file to the cloud
response = file_api.upload_file(request)
print(response.uploaded)
# How to merge specific pages of multiple PPTX files in Python
# Create and initialize api instances
documentApi = groupdocs_merger_cloud.DocumentApi.from_config(configuration)
# Input source file 1
item1 = groupdocs_merger_cloud.JoinItem()
item1.file_info = groupdocs_merger_cloud.FileInfo("python-testing/powerpoint-one.pptx")
# slide numbers of specific slides to merge
item1.pages = [1,2]
# Input source file 2
item2 = groupdocs_merger_cloud.JoinItem()
item2.file_info = groupdocs_merger_cloud.FileInfo("python-testing/powerpoint-two.pptx")
# start slide number
item2.start_page_number = 2
# end slide number
item2.end_page_number = 4
# slides range mode
item2.range_mode = "OddPages"
# Define join options
options = groupdocs_merger_cloud.JoinOptions()
options.join_items = [item1, item2]
options.output_path = "python-testing/joined-slides.pptx"
# Create join request
request = groupdocs_merger_cloud.JoinRequest(options)
# Merge pptx files
result = documentApi.join(request)
print("Successfully merged PPTX slides: " + str(result))
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_merger_cloud
# Get client_id and client_secret from https://dashboard.groupdocs.cloud after free registration.
client_id = "xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
client_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# Get File API configurations
configuration = groupdocs_merger_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "MyStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment