Edit PowerPoint Presentations using Python

Edit PowerPoint using Python

As a Python developer, you can easily edit PowerPoint presentations programmatically. You can update slide content without installing any external application using Python. This article will be focusing on how to edit PowerPoint presentations using a REST API in Python.

The following topics shall be covered in this article:

Document Editor REST API and Python SDK

For editing PPTX, I will be using the Python SDK of GroupDocs.Editor Cloud API. It allows you to programmatically edit Word processing documents, Excel sheets, or documents of other supported formats. It also provides .NETJavaPHPRubyAndroid, and Node.js SDKs as its document editor family members for the Cloud API.

You can install GroupDocs.Editor-Cloud to your Python project using the following command in the console:

pip install groupdocs_editor_cloud

Please get your Client ID and Client Secret from the dashboard before you start following the steps and available code examples. Once you have your ID and secret, add in the code as demonstrated below:

Edit PowerPoint Presentations using REST API in Python

You can edit the PowerPoint presentation by following the simple steps mentioned below:

  1. Upload the PPTX file to the Cloud
  2. Edit the uploaded file
  3. Download the updated file

Upload the Document

First of all, upload the PowerPoint presentation to the Cloud using the code example given below:

As the result, the PPTX file will be uploaded to Cloud Storage and will be available in the files section of your dashboard.

Edit PowerPoint Presentation using Python

Please follow the steps mentioned below to edit the PowerPoint presentation programmatically.

  • Create File API and Edit API instances
  • Provide the input file path
  • Provide PresentationLoadOptions
  • Load a file with the Load method of Edit API
  • Download HTML document using Download File method of File API
  • Edit the downloaded HTML Document
  • Upload HTML back using Upload File method of File API
  • Provide PresentationSaveOptions to Save in PPTX
  • Save HTML back to PPTX using Save method of Edit API

The following code snippet shows how to update a PowerPoint presentation document using a REST API.

Edit PowerPoint presentation using Python
Edit PowerPoint presentation using Python

Download the Updated File

The above code sample will save the edited PowerPoint presentation (PPTX) file on the cloud. You can download it using the following code sample:

Update Images in PowerPoint Presentation using Python

Please follow the steps mentioned below to update the image in the PowerPoint presentation programmatically.

  • Create File API and Edit API instances
  • Provide the input file path
  • Provide PresentationLoadOptions
  • Load a file with the Load method of Edit API
  • Download HTML document using Download File method of File API
  • Upload image file
  • Edit the downloaded HTML Document and update the image
  • Upload HTML back using Upload File method of File API
  • Provide PresentationSaveOptions to Save in PPTX
  • Save HTML back to PPTX using Save method of Edit API

The following code snippet shows how to update an image on the PowerPoint presentation slide using a REST API.

Update image in PowerPoint presentation slide
Update image in PowerPoint presentation slide

The API creates an HTML file at the defined PresentationLoadOptions.output_path. All the resource files associated with created HTML file are placed in a files subdirectory prefixed with the input file name such as “sample.files” in this case. You need to upload the image in this directory and then replace it with the target image. All the images on the slide are named Picture 2, Picture 3, etc in the “src” attribute.

Try Online

Please try the following free online PowerPoint editing tool, which is developed using the above API. https://products.groupdocs.app/editor/pptx

Conclusion

In this article, you have learned how to edit PowerPoint presentations on the cloud with Document Editor REST API using Python. You also learned how to programmatically upload the PPTX file on the cloud and then download the updated file from the cloud. You can learn more about GroupDocs.Editor Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.

See Also