带有TCPDF的额外空白页面 [英] Extra blank page with TCPDF
问题描述
我使用TCPDF将php生成的页面转换为对每条记录使用div和style =page-break-after:always的mysql查询,这些记录的长度会有所不同。
当我使用下面的代码将它们转换为pdf时,最后会得到一个额外的空白页面?当我打印一个没有style =page-break-after的记录时:总是没有空白页?
< ?php
error_reporting(0); //不要在PDF中显示错误
ob_clean(); //清除以前的输出
ob_start(); //开始新的输出缓冲区
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,'签名_____________________________________________',0,1,'L',0,'',0,false,'T','B');
$ this-> Cell(0,15,'Print Name ________________________',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);
$ html = ob_get_contents();
ob_clean();
$ html = preg_replace(/ \s\s + /,'',$ html); //删除多余的空格
$ pdf-> writeHTML($ html,true,false,true,false,'');
$ pdf-> lastPage();
$ pdf->输出('delivery.pdf','I');
预先感谢您
彼得
尝试使用
.element: last-child {page-break-after:auto;}
其中'element'是您的CSS选择器。
I am using TCPDF to convert a page generated by php from a mysql query which has uses a div and style="page-break-after:always" for each record, these records will vary in length.
When I convert them to pdf using the below code I get an extra blank page at the end? When i print one record without the style="page-break-after:always" there is no blank page?
<?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');
Thank you in advance
Peter
Try using
.element:last-child {page-break-after:auto;}
Where 'element' is your CSS selector.
这篇关于带有TCPDF的额外空白页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!