作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正忙于一个需要大量 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');
最佳答案
您可以使用自定义 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/
我是一名优秀的程序员,十分优秀!