I want to convert an HTML file to PDF using iTextSharp.
I used this code.
I then did the following to convert it to pdf:
HTMLWorker htmlWorker = new HTMLWorker(document);
htmlWorker.Parse(new StringReader(results));
document.Close();
However, none of the CSS is parsed. Any alternatives?
18 months ago, we exhaustibly tested most of the html-to-pdf converters available (paid and free). In the end, the hands-down best html-to-pdf converter was a free, open-source program called wkhtmltopdf.
It is command-line-driven, uses the webkit rendering engine, and accurately (and more importantly, consistently) turns web pages into beautiful looking pdf’s. It also has a variety of useful command-line switches, gives you complete header/footer control, optionally creates table-of-contents pages, and runs very, very fast. AND — because it’s command line driven, it has the added bonus of easily being used for batch generation. You simply cannot go wrong.
As a sidenote, this program also has a sister program (bundled in download) called wkhtmltoimage, which works exactly the same way, but converts webpages to a variety of image formats. This has also been highly useful and we use this functionality for taking snapshots of our web-based tools when building proposals for jobs.
I’m know that I sound like a total fanboy, but I’m not. I’m simply someone that got so sick-and-tired of all the bullsh*t converters out there that I was doubly blown away when we found wkhtmltopdf. I simply cannot recommend this little program enough.