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

Nizam picture Nizam · Dec 30, 2011 · Viewed 16.6k times · Source

I'm using CakePHP 1.3 to make an online application system. I try to print a PDF document using TCPDF based on a view.

I use the code

$this->writeHTML($this->render('print') ) 

in my print controller.

The problem is that I have this

undefined index : cols

error output to the screen. What could have gone wrong?

Answer

parrker9 picture parrker9 · Feb 21, 2012

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.