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
I'm the author of the Rotativa package. It allows to create PDF files directly from razor views:
https://www.nuget.org/packages/Rotativa/
Trivial to use and you have full control on the layout since you can use razor views with data from your Model and ViewBag container.
I developed a SaaS version on Azure. It makes it even easier to use it from WebApi or any .Net app, service, Azure website, Azure webjob, whatever runs .Net.
http://www.rotativahq.com/
Free accounts available.