我在我的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
是的......我从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]) ) {
希望这会有助于其他人......
我现在也在与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
出现此错误是因为您没有设置<thead>
和
<tbody>
标记在HTML中的表格中。