How to convert a .pptx to .pdf using Python

前端 未结 5 584
我寻月下人不归
我寻月下人不归 2021-02-05 22:53

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:

5条回答
  •  一生所求
    2021-02-05 23:08

    I believe the answer has to be updated because because comtypes doesn't work anymore.

    So this is the code which works (updated version of the accepted answer) :

    import win32com.client
    
    def PPTtoPDF(inputFileName, outputFileName, formatType = 32):
        powerpoint = win32com.client.DispatchEx("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()
    

提交回复
热议问题