Convert PPTX 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 PPTX 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 PPTX presentation to a full-page image in a Word document.

Python code for converting PowerPoint to Word

with slides.Presentation("presentation.pptx") 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 PPTX to Word

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

  2. Load the PPTX 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 by using Slide.get_image.

  5. Insert each rendered image by using DocumentBuilder.insert_image, adding page breaks between slides.

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

Other Supported Conversions

You can also convert PPTX files to other supported formats.