Turning HTML into PDF is not always as simple as it is necessary to render content and then convert it. Solutions that attempt to convert HTML to style-based PDF or simplistic assumptions tend to have many limitations, such as table, img, etc.
The best alternative is probably to use a webkit HTML renderer that converts to PDF or PNG, however you prefer. The link is one of the best we have used for years in a very aggressive environment of converting everything that is document type, including with images, CSS, tables, headers and footers, custom margins, everything:
1) Install wkhtmltopdf on the server.
2) Create a script (PHP, Perl, whatever you want) that receives HTML, invoke the wkhtmltopdf command and output the application / pdf back to the client.
3) On the web page, via javascript give a POST of HTML content to the script created on the server-side.
If you are already on the server side and use PHP, there already exists a project that does this port: link
I made a direct IPC with the executable wkhtmltopdf to have full control gave no more than 10 lines (in my case in PERL). In PHP it should be pretty simple too.