从 Python 打印 Powerpoint 幻灯片

Print Powerpoint Slide from Python

我正在尝试从 Powerpoint 打印一张幻灯片。我使用以下代码访问了幻灯片:

from win32com import client
powerpoint = client.Dispatch("Powerpoint.Application")
presentation = powerpoint.presentations.Open(filepath)
slide = presentation.Slides[10]
print(slide.name)  # Just to check I have in fact got the slide

打印 Word 文档时,我只能在文档上调用 PrintOut(),但它似乎不适用于 Powerpoint。

有人有解决办法吗?

presentation.PrintOut()

打印整个演示文稿,但我只想要一张特定的幻灯片。

好的,我发现我可以使用以下方法指定一个范围:

presentation.PrintOut(From=1, To=1)

我可以循环播放幻灯片以匹配名称:

count = 1
for slide in presentation.Slides:
    if slide.name == "Slide1":
        presentation.PrintOut(From=count, To=count)
        break
    count += 1