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兩個格式的文件夾

送各位菜鳥一句:屠龍還需寶刀,裝逼還靠潘神ui

相關文章
相關標籤/搜索