博客
关于我
Python转换PPT为PDF
阅读量:804 次
发布时间:2023-03-06

本文共 1132 字,大约阅读时间需要 3 分钟。

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)
deck.Close()
def convert_files_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_folder(powerpoint, cwd)
powerpoint.Quit()

该代码用于将PowerPoint文件转换为PDF格式,适用于批量处理。代码定义了三个主要函数:

  • init_powerpoint():初始化PowerPoint应用程序并设置其可见性。
  • ppt_to_pdf():将指定文件格式的PowerPoint文件保存为PDF文件,支持设置输出格式。
  • convert_files_folder():遍历指定文件夹,找到所有PowerPoint文件并进行批量转换。
  • 代码的主要功能包括文件遍历、文件格式转换以及PowerPoint应用程序的操作,适合用于自动化处理和批量转换任务。

    转载地址:http://keafk.baihongyu.com/

    你可能感兴趣的文章
    Python 中的字符串、列表、元组和字典数据类型的特点和使用场景
    查看>>
    Python 中的属性访问器是什么?如何使用 @property 装饰器?
    查看>>
    Python 中的带宽限制
    查看>>
    Python 中的机器学习简介:多项式回归
    查看>>
    python读取grib2数据_用Python加载grib2文件
    查看>>
    Python 中的注意点_s2
    查看>>
    Python读取Excel的几种工具包(附Demo)
    查看>>
    Python 中的生成器是什么?
    查看>>
    Python 中的离线语音转文本
    查看>>
    Python读写json文件的简单实现
    查看>>
    Python 中的线程
    查看>>
    Python 中的继承机制是什么样的?
    查看>>
    python读写excel之xlrd&xlwt&xlutils组合
    查看>>
    Python 中的装饰器是什么?
    查看>>
    Python 中的装饰器是如何工作的,有哪些实际应用场景?
    查看>>
    python读excel
    查看>>
    Python 中读取 CSV 文件-ChatGPT4o作答
    查看>>
    Python 之 filecmp
    查看>>
    python请求html_使用Python请求获取HTML?
    查看>>
    Python 之匿名函数和偏函数
    查看>>