Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert PPT to PNG via python

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?)

like image 220
agiliq Avatar asked Nov 06 '22 15:11

agiliq


1 Answers

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.

like image 90
gurney alex Avatar answered Nov 15 '22 06:11

gurney alex