Merge or Split PPT in Python

Split or Merge PPT

Over the course of time, many documents are created by various people in organisations and for long-term archival purposes, they are combined together into a single unified source of information. Similarly, a document may contain too many details which cannot be shared with all the people, so as per requirement, the document can be split so that it can be shared accordingly. In this article, we are going to discuss, the details on how to split and merge PowerPoint in Python.

PPT processing SDK

Aspose.Slides Cloud is our award-winning REST API providing capabilities to the user to create, edit, process, and save major PowerPoint formats (including but not limited to PPTX, PPT, PPSX, PPTM, ODP, OTP, etc) to other popular file formats including TIFF, PDF, XPS, JPEG, HTML, etc. For more information, please visit Supported Document Formats. Furthermore, it enables you to perform a variety of other operations and their details can be found over Overview.

In order to facilitate our customers specifically using Python programming language, we have created Aspose.Slides Cloud SDK for Python which is a wrapper around Aspose.Slides Cloud, so you get all the capabilities of Cloud API within your Python code.

Installation

In order to use the Cloud SDK, the first step is to install it on your system. The SDK is available for download on PIP and GitHub. Please run the following command to perform the installation from pip

pip install asposeslidescloud

Another approach is to add dependencies directly in IDE when using PyCharm. Please search asposeslidescloud on Python Interpreter window under PyCharm -> Preferences… section.

Aspose.Slides Python

Account Subscription

We care about our customers and give vital importance to data integrity. Therefore, only the authorized users can access the APIs as well as the documents available in their cloud storage. Therefore, the first step is to create an account by visiting Aspose.Cloud dashboard. If you have GitHub or Google account, simply Sign Up. Otherwise, click on the Create a new Account button and provide the required information. Now login to the dashboard using credentials and expand the Applications section from the dashboard and scroll down towards the Client Credentials section to see Client ID and Client Secret details.

Client Credentials

Using cURL command to Merge PPT

Aspose.Slides REST API can easily be accessed via cURL commands over the terminal. So in order to access the API using cURL command, we need to first generate JSON Web Token (JWT) based on your ClientID and ClientSecret details retrieved from Aspose.Cloud dashboard. Please execute the following command in the terminal to generate the JWT token.

curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=718e4235-8866-4ebe-bff4-f5a14a4b6466&client_secret=388e864b819d8b067a8b1cb625a2ea8e" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"

Once the JWT token has been generated, please use the following command to merge PPT files already available on Cloud storage. The filename provided against PresentationPaths parameter will be merged to the source PPT file. For merge purposes, we are using PostPresentationMerge API. In the example below, output.ppt is the input PowerPoint document and Presentation1.ppt is the file to be merged.

curl -X POST "https://api.aspose.cloud/v3.0/slides/output.ppt/merge" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"PresentationPaths\": [    \"Presentation1.ppt\"  ]}"

Merge PPT in Python

The following code snippets explains the steps and details for merging two or more PPT files and generate a single concatenated file.

  • The first step is to create a Configuration object
  • Secondly, set the Client ID value to app_sid property and Client Secret details to app_key property
  • In the next step, initialize the SlidesApi object while passing the Configuration instance as an argument
  • Now create an object of PresentationsMergeRequest object while passing names of the Presentations file to be merged. The files are merged in the sequence the names are passed
  • The next step is to call PostPresentationmergeRequest method which takes input PPT, and list of PPT files to be merged (as specified in the last code line)
  • Finally, call the post_presentation_merge method of SlidesApi request

Use the cURL command to Split PPT

We can also split the PPT file to individual PowerPoint presentations using the cURL command. Please execute the following command to accomplish this requriement.

curl -X POST "https://api.aspose.cloud/v3.0/slides/test-unprotected.ppt/split?format=Pptx&from=2&to=3" \
-H  "accept: application/json" \
-H  "authorization: Bearer <JWT Token>" \
-H  "Content-Type: application/json" \
-d "{  \"Format\": \"pptx\"}"

The sample PPT used in above example can be downloaded from test-unprotected.ppt.

Split PPT in Python

The following code snippet explains the steps on how to split individual slides of PowerPoint as separate presentation files.

  • First of all, create a Configuration object
  • Secondly, set the Client ID value to app_sid property and Client Secret details to app_key property
  • In the next step, initialize the SlidesApi object while passing the Configuration instance as an argument
  • Penultimate, create an object of PostSlidesSplitRequest API which takes input PPT, output format value, From and To slide number against which the split operation will be performed
  • Finally, call the post_slides_split(..) method and pass the PostSlidesSplitRequest object created above as an argument to initiate the PPT split operation

In case you need to save the split output in other formats, simply provide a related argument to PostSlidesSplitRequest object. The possible value can be from the list shown below

Conclusion

In this article, we have discussed the steps on how to merge various PPT files into a single combined document and also, how to split individual slides of PowerPoint into separate PPT files. The Cloud API can also be tested using a swagger interface within a web browser. Also, please note that the complete source code of Aspose.Slides Cloud SDK for Python is open-source and can be downloaded from GitHub.

Should you have any related query while using the API, please feel free to contact via free customer support forum.

Related Links

In order to read more about the exciting features being offered by Aspose.Slides Cloud API, we recommend visiting the following links