ppt文件批量转pdf文件

该脚本使用Python的win32com.client库,通过Powerpoint应用接口将指定文件夹中的所有PPT和PPTX文件转换成PDF格式,便于在PAD上查看。
摘要由CSDN通过智能技术生成

听申论课的时候发现站长的课件都是单个ppt文件,想合并成一个pdf文件放在pad上看,于是就用gpt写了一个脚本,输入文件夹地址,检测里面的ppt文件并转化成pdf文件。

import os
import win32com.client

def ppt_to_pdf(input_folder):
    powerpoint = win32com.client.Dispatch("Powerpoint.Application")
    
    ppt_files = [file for file in os.listdir(input_folder) if file.lower().endswith((".ppt", ".pptx"))]
    
    for ppt_file in ppt_files:
        ppt_path = os.path.join(input_folder, ppt_file)
        pdf_file = os.path.splitext(ppt_file)[0] + ".pdf"
        pdf_path = os.path.join(input_folder, pdf_file)
        
        if not os.path.exists(pdf_path):
            presentation = powerpoint.Presentations.Open(ppt_path)
            presentation.SaveAs(pdf_path, 32)  # 32 is the value for PDF format
            presentation.Close()

    powerpoint.Quit()

if __name__ == "__main__":
    folder_address = "C:\\你的文件夹路径"  # 在这里替换成你想要的文件夹地址
    ppt_to_pdf(folder_address)

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值