将pptx转换为PNG图片。

huangapple go评论89阅读模式
英文:

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的回答:

  1. 安装comtypes库(使用命令pip install comtypes)。
  2. 在设置folder_to_save_pngspptx_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:

  1. Install the comptypes library (i.e. pip install comtypes)
  2. 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.

huangapple
  • 本文由 发表于 2020年1月6日 23:19:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/59614611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定