HTML2PDF : undefined offset

While this blog is mainly about code-examples, I’d like to post an occasional bugfix when it’s a nasty one. This is one of them.

The HTML2PDF library for PHP is a great library for converting HTML to PDF. I ran into a problem in an application where an exception was thrown by this library with the vague message ‘Undefined offset 5‘.

At first I thought it was my code, but as I wasn’t using any arrays I started inspecting the HTML closer and finally noticed a table-element was causing the problem. Because of a miscalculation with the rowspan-attribute of one of the table-cells, not all the table-rows contained an equal amount of columns. This explains the undefined offset issue; the library has to convert to table to pdf and uses arrays in the background to convert the table data. A mismatch in columns will break this code. The library does not account for invalid html in this case and continues on the assumption the table-markup is correct. This explains the vague error message.

I Hope this solves your issue. If this is not the case, start leaving out parts of your HTML untill the error dissapears to discover what element might be causing it.

Published by

Justin

Justin

Hi there! I'm a software engineer currently employed at a company in The Hague in the Netherlands. You can find out more about me and my qualifications on LinkedIn (http://nl.linkedin.com/pub/justin-van-schaick/26/1b0/210). I started this blog in order to share interesting code snippets and tutorials on mainly Javascript, PHP and related frameworks. The internet is an invaluable resource for programmers and unfortunately there's never enough documentation out there. So this is me trying to contribute to that.

Leave a Reply