当前位置:   article > 正文

27行代码批量将PPT转成PDF,属实强大啊!_python ppt转pdf

python ppt转pdf

 

 

文章来源:https://m.pythontab.com/article/1246

 

 

代码:

  1. import comtypes.client
  2. import os
  3. def init_powerpoint():
  4. powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
  5. powerpoint.Visible = 1
  6. return powerpoint
  7. def ppt_to_pdf(powerpoint, inputFileName, outputFileName, formatType = 32):
  8. if outputFileName[-3:] != 'pdf':
  9. outputFileName = outputFileName + ".pdf"
  10. deck = powerpoint.Presentations.Open(inputFileName)
  11. deck.SaveAs(outputFileName, formatType) # formatType = 32 for ppt to pdf
  12. deck.Close()
  13. def convert_files_in_folder(powerpoint, folder):
  14. files = os.listdir(folder)
  15. pptfiles = [f for f in files if f.endswith((".ppt", ".pptx"))]
  16. for pptfile in pptfiles:
  17. fullpath = os.path.join(cwd, pptfile)
  18. ppt_to_pdf(powerpoint, fullpath, fullpath)
  19. if __name__ == "__main__":
  20. powerpoint = init_powerpoint()
  21. cwd = os.getcwd()
  22. convert_files_in_folder(powerpoint, cwd)
  23. powerpoint.Quit()

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号