TCPDF - Header image only displays on first page

时间:2018-10-05 09:17:19

标签: tcpdf

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?

Thanks

3 个答案:

答案 0 :(得分:2)

如上所述,这是一个tcpdf错误。就我而言,标题中有两个徽标,一个为png,另一个为jpg。该问题仅发生在.png上。将图像类型从png更改为jpg解决了该问题。

答案 1 :(得分:0)

我认为与页眉/页脚无关,但我认为TCPDF有一个错误,即如此处TCPDF - image displayed only once所述,多次加载相同的图像文件时,图像功能被破坏了{p} 在实际版本tecnickcom / tcpdf:6.2.26上也存在

bug

我通过将图像加载到外部并将其作为字符串传递给函数来解决此问题。

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);
}

答案 2 :(得分:0)

我通过使用这样的base64编码的字符串解决了这个问题:

$image = base64_encode(file_get_contents('path_to_image'));

然后您可以像这样使用它:

<img src="@<?= $image ?>" />