与TCPDF额外的空白页(Extra blank page with TCPDF)

2019-10-16 13:58发布

我使用TCPDF通过从MySQL查询具有PHP生成的页面转换使用DIV和风格=“分页-后:始终以”为每个记录,这些记录将在长度上有所不同。

当我使用下面的代码转换为PDF我在最后得到一个额外的空白页? 当我打印一个记录,而不风格=“分页-后:总是”没有空白页?

<?php
error_reporting(0); //Don't show errors in the PDF 
ob_clean(); //Clear any previous output 
ob_start(); //Start new output buffer 
require_once('../pdf/config/lang/eng.php');
require_once('../pdf/tcpdf.php');
class MYPDF extends TCPDF {
public function Header() {
}
public function Footer() {
    $this->SetY(-50);
    $this->SetFont('helvetica', 'I', 8);
    $this->Cell(0, 5, 'Some text',0, 1, 'L', 0, '', 0, false, 'T', 'T');
$this->Cell(0, 5, 'Some text',0, 1, 'L', 0, '', 0, false, 'T', 'T');
    $this->SetFont('helvetica', 'I', 12);
$this->Cell(0, 15, 'Signed_____________________________________________',0, 1, 'L',                0, '', 0, false, 'T', 'B');
$this->Cell(0, 15, 'Print Name_____________________________________________ Date________________________',0, 1, 'L', 0, '', 0, false, 'T', 'B');    
}
}
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Author');
$pdf->SetTitle('Delivery Notes');
$pdf->SetSubject('Delivery Notes');
$pdf->SetKeywords('TCPDF, PDF,');
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(10, 10, 10);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setLanguageArray($l);
$pdf->SetFont('helvetica', '', 10);
$pdf->AddPage('P', 'LETTER');
$include=$_POST['include'];
include($include); 
$html = ob_get_contents();
ob_clean();
$html = preg_replace("/\s\s+/", '', $html); //Strip excess whitespace 
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->lastPage();
$pdf->Output('delivery.pdf', 'I');

先感谢您

彼得

Answer 1:

尝试使用

.element:last-child {page-break-after:auto;}

凡“元素”是你的CSS选择器。



文章来源: Extra blank page with TCPDF
标签: php html tcpdf