-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathConvertAll.py
62 lines (41 loc) · 1.75 KB
/
ConvertAll.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
#%% Convert a Folder of PowerPoint PPTs to PDFs
# Purpose: Converts all PowerPoint PPTs in a folder to Adobe PDF
# Author: Matthew Renze
# Usage: python.exe ConvertAll.py input-folder output-folder
# - input-folder = the folder containing the PowerPoint files to be converted
# - output-folder = the folder where the Adobe PDFs will be created
# Example: python.exe ConvertAll.py C:\InputFolder C:\OutputFolder
# Note: Also works with PPTX file format
#%% Import libraries
import sys
import os
import comtypes.client
#%% Get console arguments
input_folder_path = sys.argv[1]
output_folder_path = sys.argv[2]
#%% Convert folder paths to Windows format
input_folder_path = os.path.abspath(input_folder_path)
output_folder_path = os.path.abspath(output_folder_path)
#%% Get files in input folder
input_file_paths = os.listdir(input_folder_path)
#%% Convert each file
for input_file_name in input_file_paths:
# Skip if file does not contain a power point extension
if not input_file_name.lower().endswith((".ppt", ".pptx")):
continue
# Create input file path
input_file_path = os.path.join(input_folder_path, input_file_name)
# Create powerpoint application object
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
# Set visibility to minimize
powerpoint.Visible = 1
# Open the powerpoint slides
slides = powerpoint.Presentations.Open(input_file_path)
# Get base file name
file_name = os.path.splitext(input_file_name)[0]
# Create output file path
output_file_path = os.path.join(output_folder_path, file_name + ".pdf")
# Save as PDF (formatType = 32)
slides.SaveAs(output_file_path, 32)
# Close the slide deck
slides.Close()