Convert PPT to Word in Python

Python APIs for converting PowerPoint presentation slides to Word documents without Microsoft Office

Convert PowerPoint to Word using Aspose.Slides and Aspose.Words

Aspose.Slides for Python via .NET and Aspose.Words for Python via .NET let you process PowerPoint presentations and Word documents programmatically. To convert a PPT file to Word, render each slide by using Slide.get_image, insert the resulting image into a document with DocumentBuilder.insert_image, and save the document in DOCX format.

Convert PowerPoint to Word in Python

The following example converts every slide in a PPT presentation to a full-page image in a Word document.

Python code for converting PowerPoint to Word

with slides.Presentation("presentation.ppt") as presentation:
    document = words.Document()
    document_builder = words.DocumentBuilder(document)

    slide_size = presentation.slide_size.size
    document_builder.page_setup.page_width = slide_size.width
    document_builder.page_setup.page_height = slide_size.height
    document_builder.page_setup.left_margin = 0
    document_builder.page_setup.right_margin = 0
    document_builder.page_setup.top_margin = 0
    document_builder.page_setup.bottom_margin = 0

    image_scale = 2
    slide_count = len(presentation.slides)

    for slide_index, slide in enumerate(presentation.slides):
        with slide.get_image(image_scale, image_scale) as slide_image:
            with io.BytesIO() as image_stream:
                slide_image.save(image_stream, slides.ImageFormat.PNG)
                image_data = image_stream.getvalue()

        page_width = document_builder.page_setup.page_width
        page_height = document_builder.page_setup.page_height
        document_builder.insert_image(image_data, page_width, page_height)

        if slide_index < slide_count - 1:
            document_builder.insert_break(words.BreakType.PAGE_BREAK)

    document.save("presentation.docx")

How to convert PPT to Word

  1. Install Aspose.Slides for Python via .NET and Aspose.Words for Python via .NET.

  2. Load the PPT file into a Presentation instance, and create Document and DocumentBuilder instances.

  3. Match the Word page size and margins to Presentation.slide_size.

  4. Render each Slide with Slide.get_image and insert the image by using DocumentBuilder.insert_image.

  5. Save the resulting DOCX file by using Document.save.

Other Supported Conversions

You can also convert PPT files to other supported formats.