Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 669
Nizam Avatar asked Dec 30 '11 03:12

Nizam


People also ask

How does TCPDF determine number of columns in a table?

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.

What does TCPDF do with <THead>?

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.

Why can't I view wrong or incomplete HTML in TCPDF?

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? Show activity on this post.

Is it possible to send HTML code to TCPDF?

and send that to TCPDF, everything comes out just fine. TCPDF requires valid XHTML code. You must clean up your HTML code before submitting it to TCPDF. I am. The code sent to TCPDF is:


2 Answers

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>

like image 194
Kaushik shrimali Avatar answered Sep 21 '22 07:09

Kaushik shrimali


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.

like image 38
parrker9 Avatar answered Sep 24 '22 07:09

parrker9