这是一个Python脚本,能够批量地将微软Powerpoint文件(.ppt或者.pptx)转换为pdf格式。
创新互联是一家集网站建设,平武企业网站建设,平武品牌网站建设,网站定制,平武网站建设报价,网络营销,网络优化,平武网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。使用说明
1、将这个脚本跟PPT文件放置在同一个文件夹下。
2、运行这个脚本。
全部代码
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()
文章标题:批量将ppt转换为pdf的Python代码只要27行!-创新互联
文章转载:https://www.cdcxhl.com/article18/dcghdp.html
成都网站建设公司_创新互联,为您提供软件开发、网站建设、域名注册、移动网站建设、网站导航、手机网站建设
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联