批量将ppt转换为pdf的Python代码 只要27行!
这是一个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()
相关推荐
elizabethxxy 2020-11-11
CodeAsWind 2020-11-03
Andyshrk 2020-08-29
千锋 2020-08-20
82550495 2020-08-03
demm 2020-07-28
waiwaiLILI 2020-07-20
higher0 2020-07-08
songfens 2020-07-05
hermanncain 2020-06-25
Aleks 2020-06-13
Elmo 2020-06-13
学习进步 2020-06-11
Kwong 2020-06-11
GhostLWB 2020-06-08
xmwang0 2020-06-08
菇星獨行 2020-05-15
ChenRuiyz 2020-05-15