├── PPTtoPDF_MERGER.py └── README.md /PPTtoPDF_MERGER.py: -------------------------------------------------------------------------------- 1 | #lukefire 2 | import sys 3 | import os 4 | import comtypes.client 5 | import time 6 | from PyPDF2 import PdfFileMerger 7 | import re 8 | 9 | inputFolder = sys.argv[1] #input folder path that contains ppts to convert 10 | outputFolder = inputFolder 11 | 12 | inputFolder = os.path.abspath(inputFolder) 13 | outputFolder = os.path.abspath(outputFolder) 14 | 15 | AllPPTFileNames = os.listdir(inputFolder) #get path of all the ppt files in the folder 16 | 17 | print("Converting PPTs to PDFs:") 18 | 19 | animation = ["[■□□□□□□□□□]","[■■□□□□□□□□]", "[■■■□□□□□□□]", "[■■■■□□□□□□]", "[■■■■■□□□□□]", "[■■■■■■□□□□]", "[■■■■■■■□□□]", "[■■■■■■■■□□]", "[■■■■■■■■■□]", "[■■■■■■■■■■]"] 20 | 21 | for i in range(len(AllPPTFileNames)): 22 | PPTName=AllPPTFileNames[i] 23 | if not PPTName.lower().endswith((".ppt", ".pptx")): 24 | continue 25 | 26 | PPTPath = os.path.join(inputFolder, PPTName) 27 | 28 | PPT = comtypes.client.CreateObject("Powerpoint.Application") 29 | 30 | PPT.Visible = 1 31 | 32 | slides = PPT.Presentations.Open(PPTPath) 33 | 34 | file_name = os.path.splitext(PPTName)[0] 35 | 36 | output_file_path = os.path.join(outputFolder, file_name + ".pdf") 37 | 38 | slides.SaveAs(output_file_path, 32) 39 | 40 | slides.Close() 41 | time.sleep(0.2) 42 | x=int(((i+1)/len(AllPPTFileNames))*10) 43 | if x>0: 44 | x-=1 45 | sys.stdout.write("\r" + animation[x]) 46 | sys.stdout.flush() 47 | 48 | print("\nALL PPTs Converted to PDFs Successfully!") 49 | def alphaNumOrder(string): 50 | return ''.join([format(int(x), '05d') if x.isdigit() else x for x in re.split(r'(\d+)', string)]) 51 | 52 | print("Merging PDFs:") 53 | 54 | merger = PdfFileMerger() 55 | AllFiles = os.listdir(inputFolder) 56 | AllFiles.sort(key=alphaNumOrder) 57 | #print(AllFiles) 58 | for item in range(len(AllFiles)): 59 | items=AllFiles[item] 60 | if items.endswith('.pdf'): 61 | merger.append(os.path.join(inputFolder, items)) 62 | x=int(((item+1)/len(AllFiles))*10) 63 | if x>0: 64 | x-=1 65 | sys.stdout.write("\r" + animation[x]) 66 | sys.stdout.flush() 67 | 68 | 69 | merger.write(os.path.join(outputFolder,"MergedPDF.pdf")) 70 | merger.close() 71 | print("\nPDFs Merged Successfully!") 72 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PPTs_TO_PDFs_AND_Merger 2 | A script to convert MS Office `PPT/PPTX` files to `PDF files` and then `merge` all the PDF files to a single PDF file. 3 | 4 | ## Purpose 5 | This script is intended to help students to convert multiple PPTs into PDFs and then merge all of them into single PDF file. This will also help the Linux users to view PPTs files in Linux. 6 | 7 | ## Dependencies 8 | - Microsoft Office 2013 or higher 9 | - Python > 2.5 10 | - comtypes: `pip install comtypes` 11 | - PyPDF2: `pip install PyPDF2` 12 | 13 | ## Usage 14 | Run: 15 | 16 | python PPTtoPDF_MERGER.py input_Folder_name 17 | 18 | The input_Folder_name directory will contain all the PDFs with the same name as that of their corresponding PPTs and a merged file named `MergedPDF.pdf` 19 | --------------------------------------------------------------------------------