python操作ppt转为pdf和jpg

 1 import win32com
 2 import win32com.client
 3 import sys
 4 import os
 5 
 6 ppt_root = jpg_root =sys.path[0]+"\\"
 7 
 8 
 9 def ppt2png(pptFileName):
10 
11     powerpoint = win32com.client.Dispatch('PowerPoint.Application')
12 
13     powerpoint.Visible = True
14 
15     ppt_path = ppt_root + pptFileName
16 
17     outputFileName = pptFileName[0:-4] + ".pdf"
18 
19     ppt = powerpoint.Presentations.Open(ppt_path)
20     #保存为图片
21     ppt.SaveAs(jpg_root + pptFileName.rsplit('.')[0] + '.jpg', 17)
22     #保存为pdf
23     ppt.SaveAs(jpg_root + outputFileName, 32) # formatType = 32 for ppt to pdf
24 
25     # 关闭打开的ppt文件
26     ppt.Close()
27     # 关闭powerpoint软件
28     # powerpoint.Quit()
29 
30 
31 for fn in (fns for fns in os.listdir(ppt_root) if fns.endswith(('.ppt', 'pptx'))):
32     ppt2png(fn)
33 #运行结果则会出现pdf和jpg两个格式的文件夹

送各位菜鸟一句:屠龙还需宝刀,装逼还靠潘神

posted on 2018-09-17 23:59  健步如飞的老大爷  阅读(3573)  评论(0编辑  收藏  举报

导航