zoukankan      html  css  js  c++  java
  • python 操作ppt转换为pdf

    使用python操作ppt转换为pdf

    最近拿到了一些加密的ppt文档,只能以只读的方式打开,所以就不能编辑了,也不能直接转换为pdf文档了,需要做一些转换了。

    1. 需要使用WPS 2007版的(必须是2007版的才有这个功能)将ppt文档转化为可以编辑的ppt文档。

    2. (1)可以直接使用WPS或者Power Point将可以编辑的ppt文档转换为PDF文档。

        (2)可以使用python操作ppt文档批量转化ppt为PDF文档。

    import comtypes.client
    import os
     
    def init_powerpoint():
        powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
        powerpoint.Visible = 1
        return powerpoint
     
    def ppt_to_pdf(powerpoint, inputFileName, outputFileName, formatType = 32):
        if outputFileName[-3:] != 'pdf':
            outputFileName = outputFileName + ".pdf"
        deck = powerpoint.Presentations.Open(inputFileName)
        deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf
        deck.Close()
     
    def convert_files_in_folder(powerpoint, folder):
        files = os.listdir(folder)
        pptfiles = [f for f in files if f.endswith((".ppt", ".pptx"))]
        for pptfile in pptfiles:
            fullpath = os.path.join(cwd, pptfile)
            ppt_to_pdf(powerpoint, fullpath, fullpath)
     
    if __name__ == "__main__":
        powerpoint = init_powerpoint()
        cwd = os.getcwd()
        convert_files_in_folder(powerpoint, cwd)
        powerpoint.Quit()

     3. 把代码和ppt文档放在同一个目录下,在终端运行python程序,就可以将ppt文档转换为pdf

  • 相关阅读:
    Linux終端一行命令发送邮件
    团队冲刺2.4
    团队冲刺2.3
    团队冲刺2.2
    找水王
    评价win10自带输入法——微软拼音输入法
    梦断代码阅读笔记01
    团队冲刺2.1
    第十三周总结
    第十二周总结
  • 原文地址:https://www.cnblogs.com/homle/p/11074760.html
Copyright © 2011-2022 走看看