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

  • 相关阅读:
    区块链学习(2)钱包
    区块链学习(1)密钥,公钥和地址
    Ubuntu下安装和开启telnet
    ubuntu下的ppa源使用
    tensorflow中手写识别笔记
    交叉熵解读
    Ubuntu下对executable (application/x-executable)文件创建快捷方式
    Numpy学习笔记(四)
    pycharm问题总结
    Numpy学习笔记(三)
  • 原文地址:https://www.cnblogs.com/homle/p/11074760.html
Copyright © 2011-2022 走看看