fix:添加UI界面,完善功能

This commit is contained in:
2025-12-11 11:16:09 +08:00
parent 81e3c40abb
commit f437842a81
17 changed files with 939 additions and 406 deletions

42
utils/pdf_utils.py Normal file
View File

@@ -0,0 +1,42 @@
import os
import comtypes.client
def ppt_to_pdf_single(ppt_path, pdf_path=None):
"""
单个 PPT 转 PDF
:param ppt_path: PPT 文件路径
:param pdf_path: PDF 输出路径 (可选,默认同名)
"""
ppt_path = os.path.abspath(ppt_path) # COM 接口必须使用绝对路径
if pdf_path is None:
pdf_path = os.path.splitext(ppt_path)[0] + ".pdf"
pdf_path = os.path.abspath(pdf_path)
if not os.path.exists(ppt_path):
print(f"文件不存在: {ppt_path}")
return False
powerpoint = None
try:
# 启动 PowerPoint 应用
powerpoint = comtypes.client.CreateObject("PowerPoint.Application")
powerpoint.Visible = 1 # 设为可见,否则某些版本会报错
# 打开演示文稿
deck = powerpoint.Presentations.Open(ppt_path)
# 保存为 PDF (文件格式代码 32 代表 PDF)
deck.SaveAs(pdf_path, 32)
deck.Close()
print(f"转换成功: {pdf_path}")
return True
except Exception as e:
print(f"转换失败: {str(e)}")
return False
finally:
if powerpoint:
powerpoint.Quit()