我在我的网络应用程序中使用mPDF。
我必须在Mpdf的帮助下创建发票文件。 因此,具有大量行的html表(即:如果它存在单页)会引发此错误:
警告:在MPDF56 / mpdf.php上为foreach()提供的参数无效 第11008行
我使用以下代码生成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','')
但是当我添加“margin”(即:5-8)params时,会抛出上述错误。
有人有解决方法???
我尝试过使用mPDF 5.3和5.6
答案 0 :(得分: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]) ) {
希望这会有助于其他人......
答案 1 :(得分: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
答案 2 :(得分:0)
出现此错误是因为您没有设置<thead>
和
HTML内表中的<tbody>
标签。