TCPDF如何防止多余的空白页 [英] how TCPDF prevent the extra blank page
问题描述
我有创建类来使用TCPDF来制作页面.
I have create class to make page by using TCPDF.
我需要将HTML转换为pdf,因此我使用writeHTML
和AcceptPageBreak()
.
I need to convert HTML to pdf, so I using writeHTML
and AcceptPageBreak()
.
$html
是动态更改的,可能会很长.
The $html
is Dynamically changed, could be very long.
class MY_TCPDF extends TCPDF{
public function makePage($html){
$head_image="header.jpg";
$this->SetMargins(PDF_MARGIN_LEFT, 70, PDF_MARGIN_RIGHT);
$this->setPrintHeader(false);
$this->AddPage();
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->getAutoPageBreak();
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = $head_image;
$this->Image($img_file, 0, 0, 210, 68, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
//$this->SetAutoPageBreak($auto_page_break, PDF_MARGIN_BOTTOM);
// set the starting point for the page content
$this->setPageMark();
$this->writeHTML($html, true, false, true, false, '');
$this->lastPage();
ob_start();
//Close and output PDF document
$this->Output('my.pdf', 'I');
ob_end_flush();
}
public function AcceptPageBreak() {
$this->SetMargins(PDF_MARGIN_LEFT, 10, PDF_MARGIN_RIGHT);
$this->AddPage();
return false;
}
}
问题是我生成了PDF,但是在PDF的末尾总是有一个空白页.
The problem is I genenrate PDF, but alway has a extra blank page in the end of the PDF.
我尝试使用$this->delete($this->getPage())
,但它只删除了具有内容的最后一页,并且保留了多余的空白页.看来writeHTML
将在其后创建一个分页符.
I tried use $this->delete($this->getPage())
,but it only remove last page which has content and the extra blank page remain. this seems writeHTML
will create a page break after it.
如何防止出现多余的空白页?
how to prevent this extra blank page?
推荐答案
我的答案类似于@kanti.我认为我们甚至可以在生成Output之前将默认值设置为false.
My answer is similar to @kanti. I think we can set the default to false even before the Output generation.
背景.我们看到的多余页面基本上是
Background. The extra page we see is basically
如果为true,则打印TCPDF元链接".
"If true print TCPDF meta link".
因此,默认情况下,将 TCPDF :: $ tcpdflink = true 设置为true . 我们需要的只是
so by default the TCPDF::$tcpdflink = true , is set true. All we need is
class My_PDF extends TCPDF {
public function changeTheDefault($tcpdflink) {
$this->tcpdflink = $tcpdflink;
}
}
稍后在需要时调用您的公共函数. ...
call your public function later when you need it. ...
$get_pdf = new My_PDF (your_parameters);
$get_pdf->changeTheDefault(false); # changes the default to false
祝你好运.
这篇关于TCPDF如何防止多余的空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!