convert pdf to png
Andrew MacIntyre
andymac at bullseye.apana.org.au
Tue Dec 25 22:22:02 EST 2007
Carl K wrote:
> Andrew MacIntyre wrote:
>> Grant Edwards wrote:
>>> On 2007-12-24, Carl K <carl at personnelware.com> wrote:
>>>
>>>>> If it is a multi page pdf Imagemagick will do:
>>>>>
>>>>> convert file.pdf page-%03d.png
>>>> I need python code to do this. It is going to be run on a
>>>> someone else's shared host web server, security and
>>>> performance is an issue. So I would rather not run stuff via
>>>> popen.
>>> Use subprocess.
>>>
>>> Trying to eliminate popen because of the overhead when running
>>> ghostscript to render PDF (I assume convert uses gs?) is about
>>> like trimming an elephants toenails to save weight.
>> Using ctypes to call Ghostscript's API also works well. I've only done
>> this on Windows, but it should also work on other systems with ctypes
>> support.
>>
>
> sounds good, but I have 0.0 clue what that actually means.
>
> Can you give me what you did with windows in hopes that I can figure out how to
> do it in Linux? I am guessing it shouldn't be to different. (well, hoping...)
ctypes is a foreign function interface (FFI) extension that became part
of the standard library with Python 2.5 (& is available for 2.3 & 2.4).
It is supported on Linux, *BSD & Solaris (I think) in addition to Windows.
Ghostscript for quite some time has had support for being used as a
library (DLL on Windows). There are only a small number of API functions
exported, and there is information about the net for calling these API
functions from Visual Basic. I wrote a wrapper module using ctypes for
the API based on the C header and the VB information.
To get the best rendering, some understanding of Ghostscript options is
required particularly for image format outputs (eg for anti-aliasing text).
--
-------------------------------------------------------------------------
Andrew I MacIntyre "These thoughts are mine alone..."
E-mail: andymac at bullseye.apana.org.au (pref) | Snail: PO Box 370
andymac at pcug.org.au (alt) | Belconnen ACT 2616
Web: http://www.andymac.org/ | Australia
More information about the Python-list
mailing list