OdeToCode IC Logo

Convert A Directory Of PowerPoint Slides To PDF With Python

Wednesday, June 26, 2013

There are many ways to automate Microsoft Office programs, but Python might be the prettiest:

import sys
import os
import glob
import win32com.client

def convert(files, formatType = 32):
    powerpoint = win32com.client.Dispatch("Powerpoint.Application")
    powerpoint.Visible = 1
    for filename in files:
        newname = os.path.splitext(filename)[0] + ".pdf"
        deck = powerpoint.Presentations.Open(filename)        
        deck.SaveAs(newname, formatType)

files = glob.glob(os.path.join(sys.argv[1],"*.ppt?"))

This script is using Python for Windows extensions.