英文:
convert pptx into PNGs
问题
有没有一种方法可以使用Python将pptx
文件转换为每个幻灯片的png
文件?
我在考虑将pptx转换为pdf,然后将每个页面转换为png,但不确定是否是最佳方法。
英文:
Is there a way of converting a pptx
file into png
files for each slide using Python?
I was thinking of converting pptx into pdf and then converting each pages into png but not sure if it is the optimal way.
答案1
得分: 1
在Windows上,使用comtypes库是可能的。但对于Unix发行版来说,comtypes不受支持,所以不能说同样适用于Unix。对于Windows,如果你无法解决问题:
https://gist.github.com/littmus/6496277
也可以使用python-pptx库,但它似乎没有权限允许截取屏幕截图(如果我说错了,请纠正我)。与此同时,对我来说,这是一个非常有趣的问题,因为有很多关于这个问题的讨论帖子,如果你找到答案,请在这里发布答案。
英文:
It's possible on windows using comtypes library. But same cannot be said for unix distributions because comtypes isn't supported in unix. For windows,if you couldn't figure it out:
https://gist.github.com/littmus/6496277
There is also python-pptx library but it doesn't have privilege for allowing to take Screenshot (Correct me if I am wrong.) In the meanwhile, this is really interesting question according to me, since there are many threads for the same, if you get it please post the answer over here.
答案2
得分: 1
为了在Windows上使save_pptx_as_png
工作,需要进行两项操作,参考natter1的回答:
- 安装
comtypes
库(使用命令pip install comtypes
)。 - 在设置
folder_to_save_pngs
和pptx_filename
路径时,要使用反斜杠而不是Python编码中常见的正斜杠。例如,使用路径C:\\users\\me\\documents\\foo.pptx
,而不是C:/users/me/documents/foo.pptx
。
如果不这样做,可能会遇到错误消息,如“需要Comptype模块来保存PNG”或COMError“系统找不到指定的路径”。
英文:
To build on natter1's answer, two things that I had to do to get save_pptx_as_png to work on Windows:
- Install the comptypes library (i.e. pip install comtypes)
- Format my folder_to_save_pngs and pptx_filename paths with backslashes rather than the forward slashes common in Python coding. e.g. C:\users\me\documents\foo.pptx rather than C:/users/me/documents/foo.pptx
If you don't do this, you may run into errors such as "Comptype module needed to save PNGs" or COMError "The system cannot find the path specified."
答案3
得分: 0
你也可以使用 python-pptx-interface - 它具有类似于 Mukesh 链接的内置函数:
from pptx_tools.utils import save_pptx_as_png
# 使用 pptx_filename 的完整路径
save_pptx_as_png(folder_to_save_pngs, pptx_filename, overwrite_folder=True)
如果文件夹已经存在,需要设置 overwrite_folder=True。在这种情况下,可能会覆盖 PNG 文件。
英文:
You could also use python-pptx-interface - it has something similar to what Mukesh linked as built in function:
from pptx_tools.utils import save_pptx_as_png
# use full path for pptx_filename
save_pptx_as_png(folder_to_save_pngs, pptx_filename, overwrite_folder=True)
overwrite_folder=True is needed, if the folder already exists. In that case, PNGs might be overwritten.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论