使用 python-pptx 打印 Powerpoint 幻灯片

使用 python-pptx 打印 Powerpoint 幻灯片

问题描述:

我一直在使用 python-pptx 来访问幻灯片(我发现它比使用 win32 流畅得多,因为它不需要打开 Powerpoint 窗口.但是,我已经检查了文档,但找不到任何方法打印幻灯片.我错过了什么吗?

I've been using python-pptx to access slides (I find it much smoother than using win32 as it doesn't need to open the Powerpoint window. However, I've checked the docs but can't find any method of printing a slide. Am I missing something?

这是我目前所拥有的:

from pptx import Presentation
prs = Presentation(path)
for slide in prs.slides:
    if slide.name == slide_I_want:
        #send slide to printer

python-pptx(故意)没有 PowerPoint 渲染器,因此无法打印幻灯片(将它们渲染到纸张/PDF).它也不能另存为 PDF、另存为 JPG 或执行任何其他需要渲染的操作(例如自动缩小文本以适应特定区域).

python-pptx (purposely) does not have a PowerPoint renderer, and so cannot print slides (render them to paper/PDF). It also can't save as PDF, save as JPG, or do anything else that requires rendering (such as automatically shrink text to fit into a particular region).

基本原理是范围和重点之一.渲染器本身就是一个复杂的软件,并且仅与(无头)PPTX 文件编辑器弱耦合,这就是 python-pptx .渲染器还与显示平台紧密耦合,这在 Python 中没有得到很好的支持,在 OS X、Linux 和 Windows 等各种操作系统上获取字体度量等内容,可能取决于显示器和/或打印机司机等

The rationale is basically one of scope and focus. A renderer is a complex piece of software all on its own, and is only weakly coupled to a (headless) PPTX file editor, which is what python-pptx is. A renderer also has tight coupling to the display platform, which is not well supported in Python, getting things like font-metrics and so forth over the various operating systems like OS X, Linux, and Windows, perhaps depending on display and/or printer drivers, etc.