matzahboy matzahboy - 1 year ago 159
Python Question

Using python to convert PNG's into PDF's

I want to write a python script to convert PNG's into 2-page pdfs (i.e. 2 PNGs per PDF). The software needs to run on both a Mac and Windows 7.

My current solution is using ReportLab, but that doesn't install easily on a Mac. According to its website, it only has a compiled version for Windows. It has a cross-platform version that requires a C compiler to install.

Is there a better way to do this (so that I don't have to install a C compiler on the Mac)? Should I use a different library, or a different language entirely? As long as I can call the program from a python script, I could use any language for the pdf creation. Or, is there a very straightforward (i.e a non-programmer could install it) C compiler that I could install on a Mac?

What do you recommend?

Answer Source

The unix program convert can help you for conversion.

convert file.png file.pdf

But you said you want to have it under windows too. PIL imaging library has a PDF module. you should try a simple

pilconvert file.png file.pdf

to put more than one image you can play with the library which is quite flexible for resizing, stitching, etc. It is also available for mac and windows

Update 2011-02-15

On my macosx, I have installed reportlab without difficulties.

% sudo easy_install reportlab
Searching for reportlab
Best match: reportlab 2.5
Processing reportlab-2.5.tar.gz

So you could use a combination of PIL and Reportlab for your own needs.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download