dongya1875 2012-04-09 08:47
浏览 139
已采纳

TCPDF的额外空白页面

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

  • 写回答

1条回答 默认 最新

  • doudaifu6083 2012-04-09 08:51
    关注

    Try using

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

    Where 'element' is your CSS selector.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在