问题描述
我正在使用 TCPDF 生成一个 2 页的 pdf 文档.
I am using TCPDF to generate a 2 page pdf document.
我在文档中添加了页眉和页脚.页眉和页脚的文本部分正确显示在每个页面上,但是当我在页眉中包含图像徽标时,它仅显示在第一页上.
I have added a header and a footer to the document. The text part of the header and footer shows up correctly on each page however when I include an image logo in the header it is only showing up on the first page.
public function Header()
{
$this->Image('/home/xxxxxx/public_html/xxxxxxxx/uploads/logo/logo.png',10,6,0,13);
$this->SetFont('helvetica','B',20);
$this->Cell(80);
$this->Cell(0,0, $project->name . ' - Project Plan',$frame,0,'R');
$this->Ln(8);
$this->SetFont('helvetica','',10);
$this->Cell(0,0, $organisation->name,$frame,0,'R');
$this->Ln(10);
}
有人知道我在这里做错了什么吗?
Does anyone have any idea what I am doing wrong here?
谢谢
推荐答案
我认为与页眉/页脚无关,但我认为 TCPPDF 存在破坏 Image 功能的错误,如此处报告的那样多次加载相同的图像文件 TCPD - 图片只显示一次
I think is not related to header/footer, but I think TCPDF has bug that broken Image function with same image file loaded multiple times as reported here TCPDF - image displayed only once
错误也存在于实际版本 tecnickcom/tcpdf:6.2.26
bug also present on actual version tecnickcom/tcpdf:6.2.26
我通过在外部加载图像并作为字符串传递给函数来解决这个问题.
I resolve this problem by loading image outside and pass to the function as string.
public function Header()
{
$this->Image('@'.file_get_contents('/home/xxxxxx/public_html/xxxxxxxx/uploads/logo/logo.png'),10,6,0,13);
$this->SetFont('helvetica','B',20);
$this->Cell(80);
$this->Cell(0,0, $project->name . ' - Project Plan',$frame,0,'R');
$this->Ln(8);
$this->SetFont('helvetica','',10);
$this->Cell(0,0, $organisation->name,$frame,0,'R');
$this->Ln(10);
}
这篇关于TCPDF - 标题图像仅显示在第一页上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!