forked from jackbrookes/batch-ppt-to-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbatch_ppt_to_pdf.py
32 lines (28 loc) · 1.08 KB
/
batch_ppt_to_pdf.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
import comtypes.client
import os
def init_powerpoint():
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
return powerpoint
def ppt_to_pdf(powerpoint, inputFileName, outputFileName, formatType = 32):
deck = powerpoint.Presentations.Open(inputFileName)
deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf
deck.Close()
def convert_files_in_folder(powerpoint, folder):
pptFolder = 'ppt'
pptPath = os.path.join(folder, pptFolder)
pdfFolder = 'pdf'
pdfPath = os.path.join(folder, pdfFolder)
files = os.listdir(pptPath)
pptfiles = [f for f in files if f.endswith((".ppt", ".pptx"))]
for pptfile in pptfiles:
pptFullPath = os.path.join(pptPath, pptfile)
name,_ = os.path.splitext(pptfile)
pdfFile = name + '.pdf'
pdfFullPath = os.path.join(pdfPath, pdfFile)
ppt_to_pdf(powerpoint, pptFullPath, pdfFullPath)
if __name__ == "__main__":
powerpoint = init_powerpoint()
cwd = os.getcwd()
convert_files_in_folder(powerpoint, cwd)
powerpoint.Quit()