加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

批量将ppt转换为pdf的Python代码 只要27行!

发布时间:2020-12-17 07:25:46 所属栏目:Python 来源:网络整理
导读:这是一个Python脚本,能够批量地将微软Powerpoint文件(.ppt或者.pptx)转换为pdf格式。 使用说明 1、将这个脚本跟PPT文件放置在同一个文件夹下。 2、运行这个脚本。 全部代码 import comtypes.clientimport osdef init_powerpoint(): powerpoint = comtypes

这是一个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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程小技巧。

您可能感兴趣的文章:

  • python实现向ppt文件里插入新幻灯片页面的方法
  • Python实现对PPT文件进行截图操作的方法
  • Python输出PowerPoint(ppt)文件中全部文字信息的方法
  • python启动办公软件进程(word、excel、ppt、以及wps的et、wps、wpp)
  • python将html转成PDF的实现代码(包含中文)
  • Python生成pdf文件的方法
  • Python实现将DOC文档转换为PDF的方法
  • Python实现批量把SVG格式转成png、pdf格式的代码分享
  • python使用reportlab实现图片转换成pdf的方法
  • 基于Python实现对PDF文件的OCR识别

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读