How to merge two PowerPoint PPTX files together in Python
If PowerPoint merging is giving you trouble, know that you are not alone. For the Python users out there, this one is for you.
Today’s solution makes use of an API, so let’s install its client now:
pip install cloudmersive-convert-api-client
Our function call for merge_document_pptx will need to include an API instantiation using a key. This is shown in the following example:
from __future__ import print_functionimport timeimport cloudmersive_convert_api_clientfrom cloudmersive_convert_api_client.rest import ApiExceptionfrom pprint import pprint# Configure API key authorization: Apikeyconfiguration = cloudmersive_convert_api_client.Configuration()configuration.api_key['Apikey'] = 'YOUR_API_KEY'# Uncomment below to setup prefix (e.g. Bearer) for API key, if needed# configuration.api_key_prefix['Apikey'] = 'Bearer'# create an instance of the API classapi_instance = cloudmersive_convert_api_client.MergeDocumentApi(cloudmersive_convert_api_client.ApiClient(configuration))input_file1 = '/path/to/file' # file | First input file to perform the operation on.input_file2 = '/path/to/file' # file | Second input file to perform the operation on (more than 2 can be supplied).try:# Merge Two PowerPoint PPTX Togetherapi_response = api_instance.merge_document_pptx(input_file1, input_file2)pprint(api_response)except ApiException as e:print("Exception when calling MergeDocumentApi->merge_document_pptx: %s\n" % e)
Notice that you may use two or more PPTX files, which will be placed in order in the merged file. This allows you to repeatedly call merge_document_pptx using the previous call’s output, thus accommodating as many files as desired. Within this library, there exists a wide variety of other functions, allowing merging of other file formats, but also format conversion, document editing, and much more.