convert pdf to png
Piet van Oostrum
piet at cs.uu.nl
Wed Dec 26 17:11:40 EST 2007
>>>>> Carl K <carl at personnelware.com> (CK) wrote:
>CK> Here is what the code looks like that generates the pdf:
>CK> buffer = StringIO()
>CK> rw = dReportWriter(OutputFile=buffer, ReportFormFile=xmlfile, Cursor=ds)
>CK> rw.write()
>CK> pdf = buffer.getvalue()
>CK> return pdf
You can pipe the pdf through ghostscript and read the png back from
ghostscript's stdout. Like:
gs -q -sDEVICE=png16m -sOutputFile=- -
Use that command in subprocess with the stdin/stdout as pipes, send
your PDF data to the process and read the PNG output back.
However you must be aware that this can deadlock if the output is large
enough. So putting the input or the output in a real file is probably safer
anyway.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list