PDF JPG PDF XML DOCX
  Product Family
PDF

PDF Format Converter via Cloud Python SDK

Export PDF to Microsoft Office® Word, Excel, PowerPoint Presentations, Images, HTML and fixed-layout formats with Aspose.PDF Cloud Python SDK

Get Started

How to Convert PDF to DOCX Using SDK for Python

In order to convert PDF to DOCX, we’ll use Aspose.PDF Cloud Python SDK This Cloud SDK assists Python programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Python programming language via Aspose.PDF REST API. Simply create an account at Aspose for Cloud and get your application information. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Python SDK. If the python package is hosted on Github, you can install directly from Github:

Installation from Github


     
    pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git

Package Manager Console Command


     
    pip install asposepdfcloud

Convert PDF to DOCX via Python SDK

The Convert PDF to DOCX method uploads a local PDF file to Aspose Cloud Storage and converts it into a DOCX document. It uses the Aspose.PDF Cloud API, authenticates with AppSecret and AppKey, uploads the input PDF, requests the conversion in “Flow” mode for better text reflow, and saves the resulting DOCX file locally as sample.docx. Finally, it outputs the size of the converted file in bytes.

 

This sample code shows PDF to DOCX conversion via Cloud Python SDK Conversion


    from asposepdfcloud import PdfApi, ApiClient, DocFormat
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfToDocxConvert:
        """Class for converting from PDF to DOCX using Aspose PDF Cloud API."""
        def convert(self):
            """Convert PDF to Docx."""
            localFolder = "C:\Samples"
            storagePdfName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_docx_convert.docx"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))

            if self.pdf_api:
                file_path = localFolder + "/" + storagePdfName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storagePdfName), file_path)
                    
                opts = { 
                    "folder": storageTempFolder,
                    "format": DocFormat.DOCX
                }

                try:
                    response = self.pdf_api.put_pdf_in_storage_to_doc(storagePdfName, os.path.join(storageTempFolder, outputFileName), **opts)

                    if response.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + outputFileName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"pdf_docx_convert(): PDF successfully converted to DOCX: '{outputFileName}'.")
                    else:
                        logging.error(f"pdf_docx_convert(): Failed to convert PDF to DOCX. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"pdf_docx_convert(): Error while converting PDF: {e}")
 

Save PDF as XLSX Files via Python SDK

The Convert Pdf To Xlsx method uploads a local PDF file to Aspose Cloud Storage and converts it into an Excel (XLSX) spreadsheet. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, performs the conversion, saves the result locally as sample.xlsx, and then prints the file size of the converted spreadsheet in bytes.

 

This sample code shows PDF to XLSX conversion via Cloud Python SDK Conversion


    from asposepdfcloud import PdfApi, ApiClient
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfToExcelConvert:
        """Class for converting from PDF to XLSX using Aspose PDF Cloud API."""
        def convert(self):
            """Convert PDF to XLSX."""
            localFolder = "C:\Samples"
            storagePdfName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_excel_convert.xlsx"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))

            if self.pdf_api:
                file_path = localFolder + "/" + storagePdfName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storagePdfName), file_path)
                    
                opts = { "folder": storageTempFolder }

                try:
                    response = self.pdf_api.put_pdf_in_storage_to_xlsx(storagePdfName, os.path.join(storageTempFolder, outputFileName), **opts)

                    if response.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + outputFileName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"pdf_excel_convert(): PDF successfully converted to XLSX: '{outputFileName}'.")
                    else:
                        logging.error(f"pdf_excel_convert(): Failed to convert PDF to XLSX. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"pdf_excel_convert(): Error while converting PDF: {e}")
 

Convert PDF to PowerPoint Presentations via Python SDK

The Convert Pdf To Pptx method uploads a local PDF file to Aspose Cloud Storage and converts it into a PowerPoint (PPTX) presentation. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, processes the conversion, saves the output locally as sample.pptx, and prints the size of the generated presentation in bytes.

 

This sample code shows PDF to PowerPoint conversion via Cloud Python SDK Conversion


    from asposepdfcloud import PdfApi, ApiClient
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfToPowerpointConvert:
        """Class for converting from PDF to PPTX using Aspose PDF Cloud API."""
        def convert(self):
            """Convert PDF to PPTX."""
            localFolder = "C:\Samples"
            storagePdfName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_powerpoint_convert.pptx"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))

            if self.pdf_api:
                file_path = localFolder + "/" + storagePdfName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storagePdfName), file_path)
                    
                opts = { "folder": storageTempFolder }

                try:
                    response = self.pdf_api.put_pdf_in_storage_to_pptx(storagePdfName, os.path.join(storageTempFolder, outputFileName), **opts)

                    if response.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + outputFileName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"pdf_powerpoint_convert(): PDF successfully converted to PPTX: '{outputFileName}'.")
                    else:
                        logging.error(f"pdf_powerpoint_convert(): Failed to convert PDF to PPTX. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"pdf_powerpoint_convert(): Error while converting PDF: {e}")
 

Portable Document Format PDF to HTML Conversion via Python SDK

The Convert Pdf To Html() method uploads a local PDF file to Aspose Cloud Storage and converts it into an HTML format. Using the Aspose.PDF Cloud API with AppSid and AppSecret, it uploads the PDF, performs the conversion, saves the output as a ZIP archive (sample-html.zip) containing the HTML and related resources, and prints the size of the generated file in bytes.

 

This sample code shows PDF to HTML conversion via Cloud Python SDK Conversion


    from asposepdfcloud import PdfApi, ApiClient, OutputFormat
    import shutil
    import os
    import json
    from pathlib import Path
    import logging

    # Configure logging
    logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

    class PdfToHtmlConvert:
        """Class for converting from PDF to HTML using Aspose PDF Cloud API."""
        def convert(self):
            """Convert PDF to HTML."""
            localFolder = "C:\Samples"
            storagePdfName = "sample.pdf"
            storageTempFolder = "TempPdfCloud"
            outputFileName = "output_html_convert.zip"

            # Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
            self.pdf_api = PdfApi(ApiClient(AppSecret, AppSid))

            if self.pdf_api:
                file_path = localFolder + "/" + storagePdfName
                self.pdf_api.upload_file(os.path.join(storageTempFolder, storagePdfName), file_path)
                    
                opts = { "folder": storageTempFolder, "output_format": OutputFormat.ZIP }

                try:
                    response = self.pdf_api.put_pdf_in_storage_to_html(storagePdfName, os.path.join(storageTempFolder, outputFileName), **opts)

                    if response.code == 200:
                        temp_file = self.pdf_api.download_file(storageTempFolder + '/' + outputFileName)
                        local_path = localFolder + '/' + outputFileName
                        shutil.move(temp_file, local_path)
                        logging.info(f"pdf_html_convert(): PDF successfully converted to HTML: '{outputFileName}'.")
                    else:
                        logging.error(f"pdf_html_convert(): Failed to convert PDF to HTML. Response code: {response.code}")
                except Exception as e:
                    logging.error(f"pdf_html_convert(): Error while converting PDF: {e}")
 
  • Other Supported Conversions

    You can also convert many other file formats

    {
    PDF TO WORD (Microsoft Word DOC & DOCX)
    PDF TO EXCEL (Microsoft Excel)
    EPUB TO PDF (E-book Format)
    PDF TO JPEG (JPEG Image)
    JPEG TO PDF (JPEG Image)
    PDF TO PNG (Portable Network Graphics)
    GIF TO PDF (Graphical Interchange Format)
    BMP TO PDF (Bitmap Image)
    EMF TO PDF (Enhanced Metafile Format)
    PDF TO PPTX (Open XML presentation Format)
    PDF TO MHT (Hyper Text Markup Language)
    PDF TO MHT (MIME HTML web archive file format)
    MHT TO PDF (Hyper Text Markup Language)
    PDF TO XPS (XML Paper Specifications)
    PS To PDF (PostScript vector graphics)
    PDF TO SVG (Scalable Vector Graphics)
    MD to PDF (Markdown)
    PCL to PDF (Printer Command Language)
    PDF TO TeX (LaTeX Output Text)