tags:

views:

5596

answers:

8

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.

+2  A: 

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).

Norman Ramsey
+1  A: 

I doubt there is anything out there that will do this. There are multiple browsers created for displying HTML with CSS created by multi-million/billion dollar companies and they can't seem to agree how to render it.

I don't imagine anyone is making a free library that would interpret this sort of rendering and convert it to PDF. (I doubt anyone is making a non-free library that does it).

Jeff Martin
+3  A: 

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

Charlie Martin
A: 

Do you see :

  • www.xhtml2pdf.com
  • code.google.com/p/wkhtmltopdf/

They look as PrinceXML

PS link are not enable because i can't post more one link :/

azerttyu
+1  A: 

See https://xhtmlrenderer.dev.java.net/

Danesh Forouhari
A: 

You won't find a decent open source HTML to PDF converter. Most solutions are not free.

A V
Please provide some quality answers to the community before spamming your software. You'll find if you don't you are going to end up doing yourself more harm than good.
Will
+1  A: 

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

AffineMesh94464
+2  A: 

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.

isaac