Convert PPT to PNG via python

99封情书 提交于 2020-01-24 06:33:28

问题


I want to convert PPT to png, or other image formats using Python.

This question has been asked on SO, but essentially recommends running OpenOffice in headless X server, which was an absolute pain last time I used it. (Mostly due to hard to replicate bugs due to OO crashing.)

Is there any other way, (Hopefully using Linux CLI utilities only, and pure Python above them?)


回答1:


A basic workflow :

  • convert your ppt to pdf by using a pdf printer from PowerPoint or OpenOffice's built in PDF converter

  • use ghostscript to convert the pdf to png or other image format (something along the line of gs -dSAFER -dBATCH -dNOPAUSE -sDEVICE=png16m -r100 -sOutputFile=out.png in.pdf)

You can use Python to script this (and pilot OOo / MSPP using Uno / COM), or any script you want.

As far as I know, there is no Python library handling PPT files or converting PDF files to PNG.

As for the OOo crash handling, I would catch Exceptions and attempt a restart of OOo when such event occurs (and probably skip the file, adding it to a list of suspicious files requiring manual processing).

You may find this article http://www.linuxjournal.com/node/1007788 interesting as it provides a class which uses an existing OOo instance to connect or launches one if required in a transparent fashion. It comes with an example of xls -> csv conversion (http://www.linuxjournal.com/content/convert-spreadsheets-csv-files-python-and-pyuno) which can be used as a basis for the conversion you want to attempt.



来源:https://stackoverflow.com/questions/2443464/convert-ppt-to-png-via-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!