警告:在第11008行的mpdf.php中为foreach()提供的参数无效

问题描述 投票:4回答:3

我在我的Web应用程序中使用mPDF。

我必须在Mpdf的帮助下创建发票文件。所以html表有大量行(即:如果它存在单页)引发此错误:

警告:在11008行的MPDF56 / mpdf.php中为foreach()提供的参数无效

我正在使用以下代码生成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'); 

我在Mpdf的构造函数中尝试了/不带参数。我发现mpdf与前4个参数一起使用没有任何问题......

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

但是当我添加“边距”(即:5-8)参数时,会抛出上述错误。

有没有人有这个???

我尝试过使用mPDF 5.3和5.6

php mpdf
3个回答
5
投票

是的......我从MPDF论坛得到了解决方案......

这是链接:http://www.mpdf1.com/mpdf/forum/comments.php?DiscussionID=1109&page=1#Item_0

解决方案:只需将“TableHeaderFooter”功能的第一行替换为:

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

至:

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

希望这会有助于其他人......


2
投票

我现在也在与mPDF合作。我发现你最好设置这样的边距:

$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

0
投票

出现此错误是因为您没有设置<thead><tbody>标记在HTML中的表格中。

© www.soinside.com 2019 - 2024. All rights reserved.