Skip to content

Instantly share code, notes, and snippets.

@groupdocs-cloud-gists
Last active August 14, 2022 06:19
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/1bece7c25362991f1441c121e4f9fa8c to your computer and use it in GitHub Desktop.
Save groupdocs-cloud-gists/1bece7c25362991f1441c121e4f9fa8c to your computer and use it in GitHub Desktop.
Convert PowerPoint PPT/PPTX to JPG/JPEG Images in Python

You can convert PowerPoint PPT to JPG/JPEG images programmatically on the cloud. In this article, you will learn how to convert PowerPoint PPT/PPTX to JPG/JPEG file using REST API in Python.

The following topics are covered in this article:

  1. Convert PowerPoint PPT or PPTX to JPG/JPEG REST API – Installation
  2. How to Convert PowerPoint PPT/PPTX to JPG/JPEG file in Python
# How to Convert PowerPoint PPT or PPTX to JPG/JPEG format in Python
try:
# Create an instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Define convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.storage_name = storage_name
settings.file_path = "python-testing/sample-file.pptx"
settings.format = "jpeg"
convertOptions = groupdocs_conversion_cloud.JpegConvertOptions()
convertOptions.gray_scale = True
convertOptions.from_page = 1
convertOptions.pages_count = 1
convertOptions.quality = 100
convertOptions.rotate_angle = 90
convertOptions.use_pdf = False
settings.convert_options = convertOptions
settings.output_path = "python-testing"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = convert_api.convert_document(request)
print("Successfully converted PPTX to JPEG format: " + str(response))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception while calling API: {0}".format(e.message))
# API initialization to download converted file
import shutil
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Create download file request
request = groupdocs_conversion_cloud.DownloadFileRequest("python-testing\\sample-file.jpeg", storage_name)
# Download converted file
response = file_api.download_file(request)
# Move the downloaded image jpeg file to your local directory
shutil.move(response, "H:\\groupdocs-cloud-data\\")
# Upload PowerPoint PPT/PPTX file to your cloud storage
# Create an instance of the File API
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
# Call upload file request
request = groupdocs_conversion_cloud.UploadFileRequest("python-testing\sample-file.pptx", "H:\\groupdocs-cloud-data\\sample-file.pptx", storage_name)
# Upload docx file to the cloud
response = file_api.upload_file(request)
print(response.uploaded)
# Import Python SDK in your python application from http://api.groupdocs.cloud
import groupdocs_conversion_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_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
storage_name = "InternalStorage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment