意见箱
恒创运营部门将仔细参阅您的意见和建议,必要时将通过预留邮箱与您保持联络。感谢您的支持!
意见/建议
提交建议

Python里ppt转换pdf如何实现,方法是什么

来源:恒创科技 编辑:恒创科技编辑部
2023-12-25 07:26:59
这篇文章主要介绍了Python里ppt转换pdf如何实现,方法是什么相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Python里ppt转换pdf如何实现,方法是什么文章都会有所收获,下面我们一起来看看吧。


Python里ppt转换pdf如何实现,方法是什么

这是一个Python脚本,能够批量地将微软Powerpoint文件(.ppt或者.pptx)转换为pdf格式。

使用说明

1、将这个脚本跟PPT文件放置在同一个文件夹下。

2、运行这个脚本。

全部代码

importcomtypes.client
importos
definit_powerpoint():
powerpoint=comtypes.client.CreateObject("Powerpoint.Application")
powerpoint.Visible=1
returnpowerpoint
defppt_to_pdf(powerpoint,inputFileName,outputFileName,formatType=32):
ifoutputFileName[-3:]!='pdf':
outputFileName=outputFileName+".pdf"
deck=powerpoint.Presentations.Open(inputFileName)
deck.SaveAs(outputFileName,formatType)#formatType=32forppttopdf
deck.Close()
defconvert_files_in_folder(powerpoint,folder):
files=os.listdir(folder)
pptfiles=[fforfinfilesiff.endswith((".ppt",".pptx"))]
forpptfileinpptfiles:
fullpath=os.path.join(folder,pptfile)
ppt_to_pdf(powerpoint,fullpath,fullpath)
if__name__=="__main__":
powerpoint=init_powerpoint()
cwd=os.getcwd()
convert_files_in_folder(powerpoint,cwd)
powerpoint.Quit()



上述内容具有一定的借鉴价值,感兴趣的朋友可以参考,希望能对大家有帮助,想要了解更多"Python里ppt转换pdf如何实现,方法是什么"的内容,大家可以关注群英网络的其它相关文章。
上一篇: Python里random生成随机数用法是怎样的 下一篇: 在Python中怎样写条件判断语句,有什么写法