如何在TCPDF中添加带样式的自定义页脚

时间:2017-07-18 07:24:31

标签: php css pdf footer tcpdf

我正在使用 TCPDF ,我正在尝试添加不同样式的自定义页脚,例如右侧Customer Name:颜色应为蓝色,左侧Approved By:颜色应为绿色,和页面底部显示页码。

我在pdf页面试过这个

$html_content = "<table><tr><td>Customer Name:</td><td style='color:blue;'>Suneel</td><td>Approved By:</td><td style='color:green;'>Srinu</td></tr></table></hr>"    
$tcpdf->xfootertext($html_content);

它正在工作,但它不接受样式

在TCPDF类

function Footer()
{
    $year = date('Y');
    $footertext = sprintf($this->xfootertext, $year);
    $this->writeHTMLCell(0, 0, '', '', $footertext, 0, 0, false,true, "L", true);
    $this->SetY(8);
    // Set font
    $this->SetFont('helvetica', 'I', 8);
    // Page number
    $this->Cell(0, 27, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
}

1 个答案:

答案 0 :(得分:1)

最后我找到了答案,Footer接受了我们将用不同颜色解析动态内容的所有样式。

以下是解决方案

$this->writeHTML($footertext, false, true, false, true);

而不是

$this->writeHTMLCell(0, 0, '', '', $footertext, 0, 0, false,true, "L", true);

我已经改变了writeHTML而不是writeHTMLCell,它也接受了页脚颜色。