【问题标题】:TCPDF is adding an extra blank page at the endTCPDF 在末尾添加了一个额外的空白页
【发布时间】:2017-01-21 05:29:05
【问题描述】:

我正在使用以下代码生成 pdf。在某些情况下,它会在末尾添加一个空白页(在最后一个 tr 中,如果我在 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 的 this 解决方案,但它对我不起作用。有人可以帮我解决这个额外的空白页问题吗?

【问题讨论】:

    标签: php html pdf pdf-generation tcpdf


    【解决方案1】:

    我通过使用CellMultiCell 更改我的代码解决了这个问题。 TCPDF 建议尽可能快地避免使用WriteHTML,因为它很慢。我认为这可能是问题所在,我将代码更改为使用CellMultiCell,问题就解决了。而且它真的更快。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-29
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多