TCPDF "Undefined index: cols" when using tables in view

This error showing in case you missing close tag (any tag), So check your code or you can use online tools like https://jsonformatter.org/html-validator


I run into the same problem today (even though I am not using CakePHP), and all it took to fix this problem was to add a valid <thead> element to every table that I was embedding. Apparently, TCPDF parses the <thead> element to determine the number of columns in a table when it outputs tables in PDF.

Also, I would recommend to generally check if your HTML is valid if some other errors keep occurring.

I hope this helps.


TCPDF “Undefined index: cols” when using tables in view

In some cases you may forget the closing tag or define the wrong tag, resulting in this error. This is because the tcpdf package does not allow wrong or incomplete html. I suggest that you should verify the code first. You may be missing something in your html?

Otherwise swith to using simple html <table> with <tr> and <td>


I had this problem, turns out one of my <td>'s wasn't closed.