scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.45k stars 528 forks source link

AttributeError: 'Slide' object has no attribute 'export_image' #1002

Closed JSVJ closed 3 months ago

JSVJ commented 3 months ago

I'm trying to load a PPT file and save each and every slide as a PNG image. I am getting this error when I try to use the Slide object. AttributeError: 'Slide' object has no attribute 'export_image' Can anyone advice me what to do here?

I used to work with this long back and slide.export_image() was working back then. was it removed in the current update? How to achieve this in the latest version?

Code:

ppt = Presentation('/content/drive/MyDrive/Colab Notebooks/DummyPPTs/dummy_powerpoint.pptx')
for i, slide in enumerate(ppt.slides):
    image = slide.export_image()
    image_filename = f"slide_{i + 1}.png"
    image.save(NEW_FOLDER_PATH + '/' + image_filename)
    print(f"Saved slide {i + 1} as {image_filename}")
MartinPacker commented 3 months ago

According to the docs there is no export_image method. See https://python-pptx.readthedocs.io/en/latest/api/slides.html#slide-objects.

And what would you expect it to do, given python-pptx is not running the PowerPoint (rendering) engine?

If you wanted to iterate over the images on a slide that's a different matter.

JSVJ commented 3 months ago

I see, thanks. I'd like to save all the slides as images. Is there a way to achieve this?

MartinPacker commented 3 months ago

Not within python-pptx. Possibly you have some automation available to you for screen / window grabs - on whatever platform you're on.

JSVJ commented 3 months ago

Thanks. I am searching for an option to export to pdf. Is there an option to export ppt into a pdf file?

MartinPacker commented 3 months ago

Not with python-pptx. You probably could - depending on platform - automate doing it in PowerPoint or Open Office.

JSVJ commented 3 months ago

Thanks