I have been looking to convert a .pptx file to a .pdf file through a Python script for several hours but nothing seems to be working.
What I have tried:
I found the answer with the help of this post and the answer from this question.
Note that comtypes
is only available for Windows. Other platforms will not support this.
import comtypes.client
def PPTtoPDF(inputFileName, outputFileName, formatType = 32):
powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible = 1
if outputFileName[-3:] != 'pdf':
outputFileName = outputFileName + ".pdf"
deck = powerpoint.Presentations.Open(inputFileName)
deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf
deck.Close()
powerpoint.Quit()