针对将PPT文档转换成PDF文档还是使用win32com,思路也是一样的,打开一个文档然后保存为一个PDF文档,保存的时候PDF的格式编号是32。
再强调一下,在上文的Excel转PDF的代码中,我们想要在运行代码的时候不显示程序窗口,可以将应用对象的Visible属性设置为False。但这种方式在PowerPoint这里是行不通的,想要隐藏窗口的话可以在Open()文档时候指定参数WithWindow为False,代码如下:
import os.path
from win32com.client import DispatchEx
app = DispatchEx("PowerPoint.Application")
app.DisplayAlerts = 0
abs_path = os.path.abspath(_ _ file_ _)
base_dir = os.path.dirname(abs_path)
file_path = os.path.join(base_dir,"convert_ files","转换测试文
档.pptx")
save_path = os.path.join(base_dir,"convert_ files","test.pdf")
ppt = app.Presentations.Open( file_path,WithWindow=False)
ppt.SaveAs(save_path,32)
ppt.Close()
app.Quit()