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
Essential PDF can be used to convert HTML to PDF: C# sample. The sample linked to here is ASP.NET based, but the library can be used from Windows Forms, WPF, ASP.NET Webforms, and ASP.NET MVC. The library offers the option of using different HTML rendering engines : Internet Explorer (default) and WebKit (best output).
The whole suite of controls is available for free (commercial applications also) through the community license program if you qualify. The community license is the full product with no limitations or watermarks.
Note: I work for Syncfusion.