-
Notifications
You must be signed in to change notification settings - Fork 5
/
PPTtoPDF_MERGER.py
71 lines (52 loc) · 2.15 KB
/
PPTtoPDF_MERGER.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#lukefire
import sys
import os
import comtypes.client
import time
from PyPDF2 import PdfFileMerger
import re
inputFolder = sys.argv[1] #input folder path that contains ppts to convert
outputFolder = inputFolder
inputFolder = os.path.abspath(inputFolder)
outputFolder = os.path.abspath(outputFolder)
AllPPTFileNames = os.listdir(inputFolder) #get path of all the ppt files in the folder
print("Converting PPTs to PDFs:")
animation = ["[■□□□□□□□□□]","[■■□□□□□□□□]", "[■■■□□□□□□□]", "[■■■■□□□□□□]", "[■■■■■□□□□□]", "[■■■■■■□□□□]", "[■■■■■■■□□□]", "[■■■■■■■■□□]", "[■■■■■■■■■□]", "[■■■■■■■■■■]"]
for i in range(len(AllPPTFileNames)):
PPTName=AllPPTFileNames[i]
if not PPTName.lower().endswith((".ppt", ".pptx")):
continue
PPTPath = os.path.join(inputFolder, PPTName)
PPT = comtypes.client.CreateObject("Powerpoint.Application")
PPT.Visible = 1
slides = PPT.Presentations.Open(PPTPath)
file_name = os.path.splitext(PPTName)[0]
output_file_path = os.path.join(outputFolder, file_name + ".pdf")
slides.SaveAs(output_file_path, 32)
slides.Close()
time.sleep(0.2)
x=int(((i+1)/len(AllPPTFileNames))*10)
if x>0:
x-=1
sys.stdout.write("\r" + animation[x])
sys.stdout.flush()
print("\nALL PPTs Converted to PDFs Successfully!")
def alphaNumOrder(string):
return ''.join([format(int(x), '05d') if x.isdigit() else x for x in re.split(r'(\d+)', string)])
print("Merging PDFs:")
merger = PdfFileMerger()
AllFiles = os.listdir(inputFolder)
AllFiles.sort(key=alphaNumOrder)
#print(AllFiles)
for item in range(len(AllFiles)):
items=AllFiles[item]
if items.endswith('.pdf'):
merger.append(os.path.join(inputFolder, items))
x=int(((item+1)/len(AllFiles))*10)
if x>0:
x-=1
sys.stdout.write("\r" + animation[x])
sys.stdout.flush()
merger.write(os.path.join(outputFolder,"MergedPDF.pdf"))
merger.close()
print("\nPDFs Merged Successfully!")