Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert PDF to PowerPoint PPTX Presentation using a REST API on the cloud in Python.
Convert PDF to PPTX using Python
1. Programmatically upload PDF file on the cloud
2. Convert uploaded PDF file to PPTX presentation programmatically using Python.
3. Download the output files from the cloud.
client_id = "112f0f38-9dae-42d5-b4fc-cc84ae644972"
client_secret = "16ad3fe0bdc39c910f57d2fd48a5d618"
my_storage = ""
configuration = groupdocs_conversion_cloud.Configuration(client_id, client_secret)
configuration.api_base_url = "https://api.groupdocs.cloud"
# Create necessary API instances
api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "sample.pdf"
settings.format = "pptx"
# Provide PDF load options
loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()
loadOptions.hide_pdf_annotations = True
settings.load_options = loadOptions;
# Provide PPTX convert options
convertOptions = groupdocs_conversion_cloud.PptxConvertOptions()
convertOptions.from_page = 1
convertOptions.pages_count = 2
convertOptions.zoom = 1
settings.convert_options = convertOptions
settings.output_path = "converted/"
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
response = api.convert_document(request)
# Create necessary API instances
api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare convert settings
settings = groupdocs_conversion_cloud.ConvertSettings()
settings.file_path = "sample.pdf"
settings.format = "pptx"
settings.output_path = None # leave OutputPath will result the output as document IOStream
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)
# Convert
response = api.convert_document_download(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
# Create necessary API instances
api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_secret)
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("pptx", "C:\\Files\\sample.pdf")
# Convert
response = api.convert_document_direct(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
# Create instance of the API
file_api = groupdocs_conversion_cloud.FileApi.from_config(configuration)
request = groupdocs_conversion_cloud.DownloadFileRequest("converted/sample.pptx", my_storage)
response = file_api.download_file(request)
# Move downloaded file to your working directory
shutil.move(response, "C:\\Files\\")
# Create instance of the API
fileApi = groupdocs_conversion_cloud.FileApi.from_config(configuration)
request = groupdocs_conversion_cloud.UploadFileRequest("sample.pptx", "C:\\Files\\sample.pdf", "")
response = fileApi.upload_file(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment