Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mpdf

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

like image 419
Baskar.M Avatar asked Mar 23 '23 21:03

Baskar.M


2 Answers

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...

like image 131
Baskar.M Avatar answered Apr 05 '23 20:04

Baskar.M


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
like image 33
Paul Dessert Avatar answered Apr 05 '23 22:04

Paul Dessert