如何将HTML数据放入tcpdf的头文件中? [英] How to put HTML data into header of tcpdf?

查看:93
本文介绍了如何将HTML数据放入tcpdf的头文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用tcpdf库来生成pdf文档。我使用smarty模板引擎来保存数据。以下是放入标题数据的脚本:

I'm using the tcpdf library to generate the pdf document. I'm using smarty template engine to hold the data. Below is the script to put in the header data:

// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, 'PQR', 
'XYZ');

我想将smarty模板的HTML表格内容替换为XYZ,表格内容将会是动态的(意味着每张PDF文档中的表格中的数据可能会有所不同)。

I want to put HTML table content of smarty template in place of XYZ, the table content is going to be dynamic(meaning the data in table may vary for each PDF document).

推荐答案

class MyTCPDF extends TCPDF {

    var $htmlHeader;

    public function setHtmlHeader($htmlHeader) {
        $this->htmlHeader = $htmlHeader;
    }

    public function Header() {
        $this->writeHTMLCell(
            $w = 0, $h = 0, $x = '', $y = '',
            $this->htmlHeader, $border = 0, $ln = 1, $fill = 0,
            $reseth = true, $align = 'top', $autopadding = true);
    }

}

现在,一旦你有了你的MyTCPDF对象可用,你只需要这样做来设置HTML标头内容:

Now, once you've got your MyTCPDF object available, you just need to do this to set the HTML header content:

$mytcpdfObject->setHtmlHeader('<table>...</table>');

并且HTML内容不会被硬编码到 Header()方法(对你来说更灵活)。

and the HTML content won't be hardcoded into the Header() method (more flexible for you).

这篇关于如何将HTML数据放入tcpdf的头文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆