Skip to content

Instantly share code, notes, and snippets.

@littmus
Last active March 27, 2024 14:58
Show Gist options
  • Save littmus/6496277 to your computer and use it in GitHub Desktop.
Save littmus/6496277 to your computer and use it in GitHub Desktop.
Python snippet for converting ppt/pptx file to png files. Works only in PowerPoint installed Windows!
import sys
import os
try:
from comtypes import client
except:
print "Install comtypes from http://sourceforge.net/projects/comtypes/"
sys.exit(-1)
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage : python ppt2png.py [file]"
sys.exit(-1)
f = os.path.abspath(sys.argv[1])
if not os.path.exists(f):
print "No such file!"
sys.exit(-1)
powerpoint = client.CreateObject('Powerpoint.Application')
powerpoint.Presentations.Open(f)
powerpoint.ActivePresentation.Export(f, 'PNG')
powerpoint.ActivePresentation.Close()
powerpoint.Quit()
print "Converting successfully finished."
@zx1986
Copy link

zx1986 commented Dec 6, 2018

:-(

@swefse
Copy link

swefse commented Dec 15, 2018

Worked perfectly for me - cheers!

@OOOlledj
Copy link

OOOlledj commented Dec 1, 2023

It works on Python3 with additional string before Open() method:

powerpoint.Visible = True

Else i recieved error:
Traceback (most recent call last): File "C:\Users\ooolledj\Desktop\01.12 ГОЗ\pp.py", line 22, in <module> powerpoint.Presentations.Open(f) _ctypes.COMError: (-2147188160, None, ('Presentations (unknown member) : Invalid request. The PowerPoint Frame window does not exist.', 'Microsoft Office PowerPoint 2007', '', 0, None))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment