Convert HTML to PDF using itextsharp

I struggled quite a bit to convert from HTML to PDF using iTextSharp and eventually gave up because I could not get a converted PDF that looked 100% the same as my HTML5/CSS3 page. So I'm giving you the alternative that eventually worked for me.

There is surprisingly very little options available when you are not prepared to pay for a commercial library. I had the same requirement from one of my clients(to convert from HTML to PDF) that did not want to pay for any third party tools, so I had to make a plan. This is what I did, not the best solution, but it got the job done

I downloaded the newest version of wkhtmltopdf. Unfortunately the wkhtmltopdf tool did not display some of my google graphs embedded in my HTML when converting to PDF. So I used the wkhtmltoimage tool also included to convert to a PNG, which woked as expected and displayed all the graphs. I then downloaded the newest version of imagemagick and converted the PNG to PDF. I automated this process using C#.

Unfortunately this is not the most elegant solution because you have to perform two conversions and do a bit of work to automate everything, but this is the best solution I could come up with that gave me the desired results and quality.

Of course there are lots of commercial software out there that will do a faster and better job.

Just a side note:

The web page that I had to convert was devloped in HTML5 and CSS3 using version 3 of bootstrap and it contained some google graphs and charts. Everything was converted without any problems.