ITPub博客

首页 > 大数据 > 可视化 > Python实现批量将ppt转换为pdf

Python实现批量将ppt转换为pdf

原创 可视化 作者:Alin2477305449 时间:2023-03-31 11:15:00 0 删除 编辑

这是一个Python脚本,能够批量地将微软Powerpoint文件(.ppt或者.pptx)转换为pdf格式。

使用说明

1、将这个脚本跟PPT文件放置在同一个文件夹下。

2、运行这个脚本。

全部代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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()


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69952502/viewspace-2942927/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
专注电商平台工具开发及代购代采网站建站等,地球号18179018113

注册时间:2019-11-01

  • 博文量
    43
  • 访问量
    35692