Hi Anil,
HtmlRenderer.PdfSharp is a 100% fully c# managed code, easy to use, thread safe and most importantly FREE (New BSD License) solution.
Usage
Download HtmlRenderer.PdfSharp nuget package.
Use Example Method.
public static Byte[] PdfSharpConvert(String html)
{
Byte[] res = null;
using (MemoryStream ms = new MemoryStream())
{
var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
pdf.Save(ms);
res = ms.ToArray();
}
return res;
}
A very Good Alternate Is a Free Version of iTextSharp
Until version 4.1.6 iTextSharp was licensed under the LGPL licence and versions until 4.16 (or there may be also forks) are available as packages and can be freely used. Of course someone can use the continued 5+ paid version.
I tried to integrate wkhtmltopdf solutions on my project and had a bunch of hurdles.
I personally would avoid using wkhtmltopdf based solutions on Hosted Enterprise applications for the following reasons.
First of all wkhtmltopdf is c++ implemented not c#, and you will experience various problems embedding it within your c# code, especially while switching between 32bit and 64bit builds of your project. Had to try several workarounds including conditional project building etc etc just to avoid "invalid format exceptions" on different machines.
If you manage your own virtual machine its ok. But if your project is running within a constrained environment like (Azure (Actually is impossible withing azure as mentioned by the TuesPenchin author) , Elastic Beanstalk etc) its a nightmare to configure that environment only for wkhtmltopdf to work.
wkhtmltopdf is creating files within your server so you have to manage user permissions and grant "write" access to where wkhtmltopdf is running.
Wkhtmltopdf is running as a standalone application, so its not managed by your IIS application pool. So you have to Either host it as a service on another machine or you will experience huge processing spikes and memory consumption withing your production server.
It uses temp files to generate the pdf, and in cases Like AWS EC2 which has really slow disk i/o it is a big performance problem.
The most hated "Unable to load DLL 'wkhtmltox.dll'" error reported by many users.