继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

Python实现批量将ppt转换为pdf

MMTTMM
关注TA
已关注
手记 474
粉丝 65
获赞 364

这是一个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(folder, pptfile)
  ppt_to_pdf(powerpoint, fullpath, fullpath)
if __name__ == "__main__":
 powerpoint = init_powerpoint()
 cwd = os.getcwd()
 convert_files_in_folder(powerpoint, cwd)
 powerpoint.Quit()

原文来源:https://m.pythontab.com/article/1246


打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP