Twi*_*sIT 7 background-image tcpdf
我忙于一个需要大量pdf文件的项目.因为所有这些都需要公司的设计,所以我使用带有徽标/水印的背景图像.
如果我只有1页,一切都很顺利,但是当有多个页面时,背景只在第一页上.
$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');
Run Code Online (Sandbox Code Playgroud)
所以我的$ bodyText超过1页......
是否有解决方案让每个页面都有背景?
谢谢
沃特
Mát*_*ond 21
您可以使用自定义标头功能扩展TCPDF类,并将图像添加到标头中TCPDF::Image.有关如何在TCPDF示例中执行此操作的示例
从示例:
// 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();
}
}
Run Code Online (Sandbox Code Playgroud)
而MYPDF不是TCPDF像你使用的那样使用TCPDF.我唯一不知道PDF主体是否可以与标题重叠,但我认为如果你明确指定边距和标题大小.
让我知道这个是否奏效.