当前位置: 首页 > 后端技术 > Python

Python批量将ppt转pdf

时间:2023-03-25 21:20:42 Python

将脚本和PPT文件放在同一个文件夹,运行脚本,将MicrosoftPowerpoint文件(.ppt或.pptx)批量转换为pdf格式。1导入comtypes.client2导入o??s34definit_powerpoint():5powerpoint=comtypes.client.CreateObject("Powerpoint.Application")6powerpoint.Visible=17returnpowerpoint89defppt_to_pdf(powerpoint,inputFileName,outputFileName,formatType=32):10ifoutputFileName[-3:]!='pdf':11outputFileName=outputFileName+".pdf"12deck=powerpoint.Presentations.Open(inputFileName)13deck.SaveAs(outputFileName,formatType)#formatType=32forppttopdf14deck.Close()1516defconvert_files_in_folder(powerpoint,folder):17files=os.listdir(folder)18pptfiles=[fforfinfilesiff.endswith((".ppt",".pptx"))]19forpptfileinpptfiles:20fullpath=os.path.join(cwd,pptfile)21ppt_to_pdf(powerpoint,fullpath,fullpath)2223if__name__=="__main__":24powerpoint=init_powerpoint()25cwd=操作系统。getcwd()26convert_files_in_folder(powerpoint,cwd)27powerpoint.Quit()