0

Is there a way of converting a pptx file into png files for each slide using Python?

I was thinking of converting pptx into pdf and then converting each pages into png but not sure if it is the optimal way.

Jan Christoph Terasa
  • 5,781
  • 24
  • 34
user12392864
  • 288
  • 1
  • 3
  • 11
  • 2
    Please show what you have tried. I see no relationship of this question to any of your tags. – Jan Christoph Terasa Jan 06 '20 at 15:28
  • I have no starting point, just an idea (pptx to pdf to png) – user12392864 Jan 06 '20 at 15:29
  • @JohnKorchok That’s why I ask if someone knows how to do it using pptx python library. Is it impossible ? – user12392864 Jan 06 '20 at 15:38
  • 1
    @JohnKorchok I already know how to do it using PowerPoint: you just need to Save As PNG and it ask you if you want to export each slides or just the current one. In python I don’t know how to save individual slides, if you find the answer please share with us. – user12392864 Jan 06 '20 at 15:46

3 Answers3

1

It's possible on windows using comtypes library. But same cannot be said for unix distributions because comtypes isn't supported in unix. For windows,if you couldn't figure it out:

https://gist.github.com/littmus/6496277

There is also python-pptx library but it doesn't have privilege for allowing to take Screenshot (Correct me if I am wrong.) In the meanwhile, this is really interesting question according to me, since there are many threads for the same, if you get it please post the answer over here.

mozilla-firefox
  • 864
  • 1
  • 15
  • 23
1

To build on natter1's answer, two things that I had to do to get save_pptx_as_png to work on Windows:

  1. Install the comptypes library (i.e. pip install comtypes)
  2. Format my folder_to_save_pngs and pptx_filename paths with backslashes rather than the forward slashes common in Python coding. e.g. C:\users\me\documents\foo.pptx rather than C:/users/me/documents/foo.pptx

If you don't do this, you may run into errors such as "Comptype module needed to save PNGs" or COMError "The system cannot find the path specified."

gmmu8j
  • 111
  • 1
0

You could also use python-pptx-interface - it has something similar to what Mukesh linked as built in function:

from pptx_tools.utils import save_pptx_as_png

# use full path for pptx_filename
save_pptx_as_png(folder_to_save_pngs, pptx_filename, overwrite_folder=True)  

overwrite_folder=True is needed, if the folder already exists. In that case, PNGs might be overwritten.

natter1
  • 354
  • 2
  • 10