-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPPTX2PDF.py
35 lines (26 loc) · 1.33 KB
/
PPTX2PDF.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""/*******************************************
* - Coded by Moh.Massoud
* - Problem: Converting multiple PPT files to PDF.
********************************************/"""
import os,comtypes.client,sys
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
for file in sys.argv[1:]:
flag = False
currentPath = os.path.abspath(__file__)
currentDir = os.path.dirname(currentPath)
dirWithFileName = os.path.join(currentDir, file) #creating the abs dir for the file
if dirWithFileName[-4:] == 'pptx' or dirWithFileName[-3:] == 'ppt':
powerpointWindow = powerpoint.Presentations.Open(dirWithFileName)
powerpointWindow.SaveAs(dirWithFileName[:-4] + 'pdf'
if dirWithFileName[-4:] == 'pptx'
else dirWithFileName[:-3] + 'pdf', 32) # add pdf, formatType = 32 for ppt to pdf
powerpointWindow.Close()
flag = True
print("Success" if flag else ("Fail to convert " + file))
powerpoint.Quit()
"""Note:***********************************************************
you can use pyinstaller to make an executable .exe file
so you can drag and drop the ppt files into it's icon
and the output pdf will appear next to it.
***************************************************************/"""