TCPDF在末尾添加一个额外的空白页


TCPDF is adding an extra blank page at the end

我使用以下代码生成pdf。在某些情况下,它会在末尾添加一个空白页(在最后一个tr中,如果我在td中添加更多行,它会移动到第二页但如果我在td中添加较少行,它会在末尾添加一个空白页)

下面是我的代码:
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
    require_once(dirname(__FILE__).'/lang/eng.php');
    $pdf->setLanguageArray($l);
}
// set font
$pdf->SetFont('helvetica', '', 8);
// add a page
$pdf->AddPage('P');
$html = '<style type="text/css">
    th, td{
        border:1px solid #ccc;
    }
    </style>
    <table id="maintable" border="1" cellspacing="0" cellpadding="3" style="border:1px solid #cccccc;">
         <tr bgcolor="#dddddd" nobr="true">
         <th align="center" width="40px">'.LBL_PDF_EQUIPER_ID.'</th>
         <th align="left" width="100px">'.LBL_PDF_EQUIPER_NOM_PRENOM.'</th>
         <th align="left" width="175px">'.LBL_PDF_EQUIPER_EMAIL.'</th>
         <th align="center" width="100px">'.LBL_PDF_EQUIPER_TELEPHONE.'</th>
         <th width="120px">'.LBL_PDF_EQUIPER_ADRESSE.'</th>
         </tr>';
foreach($records as $record){       
    $comm_related_set = $record->getRelatedSet('con_sec__con__COMM');
    $email = "";
    $telephone = "";
    $html .= '<tr padding="0" nobr="true">
    <td align="center" width="40px">'.trim($record->getField('con_sec__USR::__kp__UsrId__lsan')).'</td>
    <td align="left" width="100px">'.trim($record->getField('con_sec__CON::NOM_Prenom_Societe')).'</td>
    <td align="left" width="175px">'.trim(implode('<br/>', $email)).'</td>
    <td align="left" width="100px">'.trim(implode('<br/>', $telephone)).'</td>
    <td width="120px">'.preg_replace('/['n'r]/','<br/>',trim($record->getField('con_sec__con__ADDR::Address_comp_display_PHP'))).'</td>
</tr>';
}
$html .= '</table>';
// output the HTML content
//echo $html; exit;
$pdf->writeHTML($html, false, false, true, false, '');
$pdf->lastPage();
$fileName = 'Liste';
//Close and output PDF document
$pdf->Output($fileName . '.pdf', 'D');

我从stackoverflow尝试了这个解决方案,但它不适合我。有人能帮我解决这个额外的空白页问题吗?

我通过使用CellMultiCell更改代码来解决这个问题。TCPDF建议尽量避免使用WriteHTML,因为它很慢。我认为这可能是一个问题,我改变了我的代码使用CellMultiCell,问题解决了。