gpt4 book ai didi

background-image - TCPDF 自动分页符 + 背景图像

转载 作者:行者123 更新时间:2023-12-04 09:32:10 24 4
gpt4 key购买 nike

我正忙于一个需要大量 pdf 文件的项目。因为他们都需要公司的设计,所以我使用带有 Logo /水印的背景图像。

如果我只有一页,一切都很好,但是当有多个页面时,背景只在第一页。

$pdf->Image('bg/background.jpg', 0, 0, 210, 297, '', '', '', false, 0, '', false, false, 0);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setPageMark();
$pdf->SetAutoPageBreak(true);
$pdf->writeHTML($bodyText, true, true, true, true, '');
$pdf->lastPage();
$pdf->Output('doc.pdf', 'I');

所以我的 $bodyText 超过 1 页...

有没有解决方案让每个页面都有背景?

谢谢

沃特

最佳答案

您可以使用自定义 header 函数扩展 TCPDF 类,并将图像添加到 header ,使用 TCPDF::Image . TCPDF examples 中有一个关于如何执行此操作的示例

从例子:

// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->AutoPageBreak;
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = K_PATH_IMAGES.'image_demo.jpg';
$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$this->setPageMark();
}
}

并使用 MYPDF而不是 TCPDF就像你会使用 TCPDF .我唯一不知道 PDF 正文是否可以与标题重叠,但我认为如果您明确指定边距和标题大小,它可以。

让我知道这个是否奏效。

关于background-image - TCPDF 自动分页符 + 背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11309182/

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