批量将ppt转换为pdf的Python代码 只要27行!
这是一个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(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()
源码地址
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下