Last active
March 27, 2024 14:58
-
-
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!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
Worked perfectly for me - cheers!
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
:-(