views:

499

answers:

5

I have google as much as I possible, checked stackoverflow several times, and yet I can not find a good html to pdf converter that can handle css. Is there a free and open source solution (even for commercial usage)? There are many solutions, with huge variety of price ranges, but I was looking for something open source and free. I have tried PISA for Python and it works fairly well, but is not free for commercial usage. Is there anything for .Net? I have not had success with iTextSharp.

+5  A: 

I've wkhtmltopdf used on a couple of projects. http://code.google.com/p/wkhtmltopdf/. It uses the webkit rendering engine, which powers the Safari browser. You'll get completely up to date rendering just like a web browser with CSS and all.

Oh, and it's open source.

Daniel Von Fange
Do you know if there is a windows binary available?
jle
Not that I know of. It'd only dependancy is QT so if you have to build QT as well, it's going to take some time.
Daniel Von Fange
I downloaded and installed QT... took a long time... and then i tried to compile wkhtmltopdf... no success as of yet
jle
What kind of errors are you getting?
Daniel Von Fange
i got it working... it is pretty nice... just need to make a standalone now... don't want to compile qt on every computer i need it for :)
jle
Great! Glad to hear it.
Daniel Von Fange
I had to read up on the shared linking, but I figured out a way to get it standalone for all windows computers.. tested on vista and xp and it works... it works great thank you!
jle
+2  A: 

I haven't found a good FOSS solution, but I can say that PrinceXML works very well, provides quite a bit of functionality through the command-line and is priced very reasonably. IIRC, the free version appends a cover page to each PDF you produce, which may or may not be a deal-killer for you, but you should definitely check it out.

bigmattyh
+1  A: 

The fact that you're asking about C#/.NET makes me guess you're on a Windows platform, so this may not work for you, but I've had decent success using html2ps in conjunction with ps2pdf:

#! /bin/sh

TEMPDIR="/tmp"
html2ps -u $1 > $TEMPDIR'temp.ps'
ps2pdf $TEMPDIR'temp.ps' $2

That does handle CSS (at least all the CSS I've thrown at it so far) though there are some limitations if I remember right with regards to some in-line styles.

NOTE: I think these are both available on Windows via Cygwin, if that's an acceptable solution for you.

Jay
A: 

You can also try different approach like using virtual printers.

raspi
A: 

I have had stunning success using the 'PISA' xhtml2pdf tool found here: http://www.xhtml2pdf.com/

Don't be scared off by the 'xhtml' part, it accepts a large range of html input, and produces PDFs according to CSS, including CSS print extensions.

Jerub