I want to generate a PDF by passing HTML contents to a function. I have made use of iTextSharp for this but it does not perform well when it encounters tables and the layout just gets messy.
Try wkhtmtopdf. It is the best tool I have found so far.
For .NET, you may use this small library to easily invoke wkhtmtopdf command line utility.
HtmlRenderer.PdfSharp is actually a 100% completely C# managed code, simple to use, thread risk-free and most notably TOTALLY FREE remedy.
An actually easy but not simply deployable option is actually to utilize a WebBrowser control to fill the Html and after that using the Publish strategy printing to a locally put up PDF color printer. There are actually numerous totally free PDF printers on call and also the WebBrowser management is a part of the.Net structure.
First of all wkhtmltopdf is actually C++ implemented certainly not C#, and also you will definitely experience various concerns embedding it within your C# code, especially while switching over in between 32bit as well as 64bit shapes of your job. Had to try numerous workarounds featuring relative project property and so on and so on only to prevent “void format exceptions” on various equipments.
If you manage your personal online equipment its own ok. But if your task is actually operating within a constricted setting like (Azure (Actually is actually difficult withing azure as discussed by the TuesPenchin writer), Elastic Beanstalk etc) it’s a problem to configure that atmosphere simply for wkhtmltopdf to work.
wkhtmltopdf is generating reports within your web server so you must handle individual authorizations and also give “write” accessibility to where wkhtmltopdf is running.
Wkhtmltopdf is actually operating as a standalone application, thus its own not taken care of through your IIS function pool. So you have to either bunch it as a company on one more machine or you will certainly experience large handling spikes as well as mind intake withing your production web server.
It utilizes temp files to produce the pdf, and just in case Like AWS EC2 which has really slow disk i/o it is actually a large performance trouble.
The absolute most hated “Not able to load DLL ‘wkhtmltox.dll'” inaccuracy stated by numerous users.
Many HTML to PDF converter depends on IE to carry out the HTML parsing as well as rendering. When customer updates their IE, this can easily damage.
I was also looking for this a while back. I ran into HTMLDOC http://www.easysw.com/htmldoc/ which is a free open source command line app that takes an HTML file as an argument and spits out a PDF from it. It’s worked for me pretty well for my side project, but it all depends on what you actually need.
The company that makes it sells the compiled binaries, but you are free to download and compile from source and use it for free. I managed to compile a pretty recent revision (for version 1.9) and I intend on releasing a binary installer for it in a few days, so if you’re interested I can provide a link to it as soon as I post it.
Download the .exe file with the rasterize.js function found in root of exe of example folder and put inside solution.
It Even allows you to download the file in any code without opening that file also it also allows to download the file when the styles and specially jquery are applied.
Instead of parsing HTML directly to PDF, you can create an Bitmap of your HTML-page and then insert the Bitmap into your PDF, using for example iTextSharp.