我是靠谱客的博主 潇洒康乃馨,最近开发中收集的这篇文章主要介绍27行代码批量将PPT转成PDF,属实强大啊!,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

 

 

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

 

 

代码:

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

 

最后

以上就是潇洒康乃馨为你收集整理的27行代码批量将PPT转成PDF,属实强大啊!的全部内容,希望文章能够帮你解决27行代码批量将PPT转成PDF,属实强大啊!所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部