Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I asked about getting iTextSharp to render a PDF from HTML and a CSS sheet before here but it seems like that may not be possible... So I guess I will have to try something else.

Is there an open source .NET/C# library out there that can take HTML and CSS as input and render it correctly?

I must reiterate... the library MUST be free and preferably something with a fairly liberal license. I'm working with basically no budget here.

share|improve this question
The only thing I can think of is a python solution : htmltopdf.org :S – bchhun Jan 10 '09 at 5:12
Why did you answer in a comment? – bentford May 12 '10 at 21:28
Because there are so many questions similar to this one but not quite the same, I decided to try to collect a complete list of HTML to PDF converters into a community wiki question stackoverflow.com/questions/3178448/… – rjmunro Jul 5 '10 at 12:57
How do we vote to get this question re-opened? @Kev – PeterX May 16 at 23:56

closed as not constructive by Kev Mar 2 at 17:13

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 5 down vote accepted

I've always used it on the command line and not as a library, but HTMLDOC gives me excellent results, and it handles at least some CSS (I couldn't easily see how much).

Here's a sample command line

htmldoc --webpage -t pdf --size letter --fontsize 10pt index.html > index.pdf
share|improve this answer
will you please explain how to use that library. any code in either C# / VB.net – Bilal lilla May 3 '12 at 5:47
@Bilal, as it says in my answer, I've always used it on the command line and not as a library. – Norman Ramsey May 6 '12 at 2:12
just write that line that you use for conversion from html to pdf. – Bilal lilla May 10 '12 at 11:42
@Bilallilla added – Norman Ramsey May 11 '12 at 3:36
@NormanRamsey does it support RTL language based Custom TTF fonts by using @fontface? – Volatil3 Apr 21 at 13:14

This command line tool is the business! http://code.google.com/p/wkhtmltopdf

It uses webkit rendering engine(used in safari and KDE), I tested it on some complex sites and it was by far better than any other tool.

share|improve this answer
3  
In fact, it also has library version and I've implemented .NET wrapper for it github.com/gmanny/Pechkin (also on NuGet). – Gman Jul 27 '12 at 14:24

It's not open source, but you can at least get a free personal use license to Prince, which really does a lovely job.

share|improve this answer
6  
Yeah, and they put their logo on the output – Levitikon Oct 13 '11 at 21:47

We have been using html2pdf for generating highly styled PDF documents with custom fonts, for a few years now. It's a little hard to get set up, but once it is, it works great... and it's free.

http://www.tufat.com/s_html2ps_html2pdf.htm

share|improve this answer

You could try my wkhtmltopdf wrapper: https://github.com/pruiz/WkHtmlToXSharp ;)

share|improve this answer

Try ABCpdf from webSupergoo. It's a commercial solution, not open source, but the standard edition can be obtained free of charge and will do what you are asking.

ABCpdf fully supports HTML and CSS, live forms and live links. It also uses Microsoft XML Core Services (MSXML) while rendering, so the results should match exactly what you see in Internet Explorer.

The on-line demo can be used to test HTML to PDF rendering without needing to install any software. See: http://www.abcpdfeditor.com/

The following C# code example shows how to render a single page HTML document.

Doc theDoc = new Doc();
theDoc.AddImageUrl("http://www.example.com/");
theDoc.Save("htmlimport.pdf");
theDoc.Clear();

To render multiple pages you'll need the AddImageToChain function, documented here: http://www.websupergoo.com/helppdf7net/source/5-abcpdf6/doc/1-methods/addimagetochain.htm

share|improve this answer
Doesn't look like the standard edition is free anymore, "Licenses for ABCpdf .NET from only $329." – Levitikon Oct 13 '11 at 21:51
The free license is offered through a promotional scheme. If it disappears, try googling for 'websupergoo free licenses'. Note the offer is for single license only. If you need to purchase a license or additional licenses, the price is as Levitikon has said. – AffineMesh Oct 18 '11 at 10:00
Yes, @AffineMesh could you please revise your text above saying the "standard edition can be obtained free of charge". Or simply add an extra note. Incidentally, I find their license somewhat confusing: "The Owner offers you a non-exclusive, non-transferable license on the terms of this Agreement". What does this mean - do I still have to get one? – PeterX May 16 at 23:42

Not the answer you're looking for? Browse other questions tagged or ask your own question.