如果页面为空,则 Mpdf 不应显示页面
Posted
技术标签:
【中文标题】如果页面为空,则 Mpdf 不应显示页面【英文标题】:Mpdf should not display page if it's empty 【发布时间】:2019-01-30 17:20:32 【问题描述】:我使用 Mpdf 创建了一个 3 页的 pdf 文档,第一页和第三页始终包含数据,而第二页则取决于它。如果其中的数据为空,我不想显示第二页
下面是代码结构
html = 'some html code to be printed on pdf'; //1st Page
$result[] = $html;
html2 = 'some html code to be printed on pdf'; //2nd Page (It might be empty)
$result[] = $html2;
// if($pdfdetails['Test'] != "")
//
// $htmlnewpage = $html2;
// else
// $htmlnewpage = '';
//
$result[] = $html2;
// In the second pdf, if the "if" condition is true then only the second page
has to be displayed or else 3rd page should display (next page),
but it isn't working for me.
html3 = 'some html code to be printed on pdf'; //3rd Page
$result[] = $html3;
$mpdf = new mPDF("en-GB-x", [336, 190], "", "",30,30,30,30,6,3);
$mpdf->SetDisplayMode('fullpage');
$mpdf->list_indent_first_level = 0;
$i=1;
$cnt = count($result);
foreach($result as $html)
$mpdf->AddPage("", [336, 190], "", "",10,10,10,4,1,0,'L');
$mpdf->WriteHTML($html,2);
if($i < $cnt)
//$mpdf->AddPage('L');
$i++;
$mpdf->showImageErrors = true;
$mpdf->Output(test'.pdf', 'I');
【问题讨论】:
【参考方案1】:我解决了。
if($pdfdetails['Test'] != "")
$result[] = $html2;
elseif($pdfdetails['Test'] == "")
$result[] = $html3;
【讨论】:
以上是关于如果页面为空,则 Mpdf 不应显示页面的主要内容,如果未能解决你的问题,请参考以下文章