HTML2PDF issues

I was working with one of the clients site where the invoices were being converted to a pdf using mpdf library.

However, as usual, there were errors encountered, so I decided to make a post related to html to pdf conversion errors and compile all the html2pdf errors in one place. This list will keep growing as I encounter more issues.

HTML2PDF doesn’t maintain table width

I spent a lot of time figuring out the issues in my code that why wasn’t the table width being maintained when I converted a perfectly designed html page to pdf using mpdf!

Well it turned out that mpdf doesn’t respect the width in percentages for nested tables (or divs too maybe? not sure!).

So what was the solution? The solution was to figure out the nested table giving issue and then giving it a fixed with in pixels (I gave 1200px). However giving a larger width didn’t disturb the layout too.

You should test your layout by giving the best possible width and see how it goes. Do check on variable outputs for your html (if it’s dynamic) to make sure that it remains good and as expected!


I thought that this issue might be due to the table having margins or the surrounding table or tags having padding or stuff, so tried giving the table a lesser width of 50%, 70% and 90%, but none was respected by mpdf! So this sort of confirms that mpdf doesn’t respect the percentage width of a nested table (maybe other elements too? div or span or anything? Needs to be checked though!) If this is wrong or you also confirmed this, please let me know through comments!

Let me know if you have any issues regarding html to pdf conversion using mpdf or any other related issue!

Leave a Reply

Your email address will not be published.