How to convert a .pptx to .pdf using Python

前端 未结 5 587
我寻月下人不归
我寻月下人不归 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:09

    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()
    

提交回复
热议问题