gpt4 book ai didi

php - TCPDF如何防止额外的空白页

转载 作者:可可西里 更新时间:2023-11-01 00:09:10 31 4
gpt4 key购买 nike

我已经创建了使用 TCPDF 制作页面的类。

我需要将 HTML 转换为 pdf,因此我使用了 writeHTMLAcceptPageBreak()

$html 是动态改变的,可能很长。

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 的末尾总是有一个额外的空白页。

我试过使用 $this->delete($this->getPage()) ,但它只删除了最后一页有内容的页面,多余的空白页仍然存在。这似乎 writeHTML 会在它之后创建一个分页符。

如何防止这个额外的空白页?

最佳答案

我遇到了同样的问题:我修复了它:

class TCPDFextended extends \TCPDF {

public function Output($name = 'doc.pdf', $dest = 'I')
{
$this->tcpdflink = false;
return parent::Output($name, $dest);
}

}

关于php - TCPDF如何防止额外的空白页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22600329/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com