import comtypes.client
 
def ppt_to_pdf(ppt_file, output_pdf_file):
    # 创建一个PowerPoint应用程序对象
    powerpoint = comtypes.client.CreateObject("Powerpoint.Application")
    
    # 设置powerpoint应用程序不可见
    powerpoint.Visible = 1  # 1表示可见,0表示不可见
    
    # 打开PPT文件
    ppt = powerpoint.Presentations.Open(ppt_file)
    
    # 保存为PDF格式
    ppt.SaveAs(output_pdf_file, 32)  # 32是PowerPoint的内置常量,表示PDF格式
    
    # 关闭PPT文件并退出PowerPoint应用程序
    ppt.Close()
    powerpoint.Quit()
    
    # 释放对象
    del powerpoint
 
# 使用函数转换文件
ppt_file = 'example.pptx'  # PPT文件路径
output_pdf_file = 'output.pdf'  # 输出PDF文件路径
ppt_to_pdf(ppt_file, output_pdf_file)