Question

I am using mPDF in my web application.

I have to create invoice documents with the help of Mpdf.. So html table with large number of rows (ie: if it exists single page) rise this error:

Warning: Invalid argument supplied for foreach() in MPDF56/mpdf.php on line 11008

I am using following code to generate pdf:

require_once(MPDF_PATH);
$mpdf=new mPDF('c','A4','0','',2,2,2,2,1,1);
$stylesheet = file_get_contents(dirname(__FILE__).'/invoice_print.css');
$mpdf->WriteHTML($stylesheet,1);
$html .="";
$mpdf->WriteHTML($html);
$mpdf->Output("$fileName",'D'); 

I have tried with/without arguments in constructor of Mpdf. And I found mpdf works with first 4 params without any problem...

$mpdf=new mPDF('c','A4','0','')

But when I add "margins" (ie: 5-8) params, will throws error described above.

Have anyone has a fix for this???

I have tried with mPDF 5.3 and 5.6

Was it helpful?

Solution

Yep... I got a fix from MPDF forum...

here is the link: http://www.mpdf1.com/mpdf/forum/comments.php?DiscussionID=1109&page=1#Item_0

SOLUTION: Just replace "TableHeaderFooter" function's first line from:

if(($horf=='H' || $horf=='F') && !empty($content)) {

to:

if(($horf=='H' || $horf=='F') && !empty($content) && !empty($content[0]) ) {

Hope this will help others...

OTHER TIPS

I'm working with mPDF at the moment as well. What I discovered is that you're better off setting the margins like this:

$style = '<style>
@page *{
    margin-top: 2.54cm;
    margin-bottom: 2.54cm;
    margin-left: 3.175cm;
    margin-right: 3.175cm;
}
</style>';

$mpdf->WriteHTML($style); //This writes the margin styles
$mpdf->WriteHTML($output); //This writes the html output

This error appears because you didn't set the <thead> and the
<tbody> tags in the table inside your HTML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top