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
Install Aspose.Slides for Python via .NET and Aspose.Words for Python via .NET.
Load the PPT file into a
Presentationinstance, and createDocumentandDocumentBuilderinstances.Match the Word page size and margins to
Presentation.slide_size.Render each
SlidewithSlide.get_imageand insert the image by usingDocumentBuilder.insert_image.Save the resulting DOCX file by using
Document.save.
Other Supported Conversions
You can also convert PPT files to other supported formats.