2012-04-09 89 views
1

我使用TCPDF來轉換一個頁面生成的php從一個MySQL查詢使用div和style =「page-break-after:always」爲每個記錄,這些記錄將在長度。額外空白頁與TCPDF

當我使用下面的代碼將它們轉換爲pdf時,我在最後得到了一個額外的空白頁面?當我打印一個沒有style =「page-break-after的記錄時:總是」沒有空白頁?

<?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'); 

預先感謝您

彼得

回答

2

嘗試使用

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

在哪裏 '元素' 是你的CSS選擇器。

+0

謝謝你的迴應,把你的建議放到css作品中,如果我直接從php頁面打印到打印機,但仍然在php頁面發送到TCPDF時創建多餘的空白頁面 – Sherwood 2012-04-09 09:34:57

+1

然後我想刪除生成的來自TCPDF實例內PDF的最後一頁,就在輸出之前,是一個快速修復? – 2012-04-09 11:12:28

+0

解決了!總是那些簡單的事情。謝謝 – Sherwood 2012-04-09 13:33:10