如果Mpdf为空,则不应显示该页面

时间:2019-01-30 17:20:32

标签: php html html5 mpdf

我使用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 个答案:

答案 0 :(得分:0)

我解决了。

if($pdfdetails['Test'] != "")
{
$result[] = $html2;
}elseif($pdfdetails['Test'] == ""){

}

$result[] = $html3;
相关问题