如何使用从数据库中获取的数据在 TCPDF 中制作自定义动态页脚? [英] How can I make a custom dynamic footer in TCPDF with data taken from a database?

查看:31
本文介绍了如何使用从数据库中获取的数据在 TCPDF 中制作自定义动态页脚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个包含从数据库中获取的数据的动态页脚.如何扩展TCPDF 类来放入这些数据?

I would like to make a dynamic footer containing data taken from a database. How to extend TCPDF class to put those data in?

// my DB stuff here
$datafromdb = getDataFromDB();

 class MYPDF extends TCPDF {
    // Page footer
    public function Footer() {
        // Position at 10 mm from bottom
        $this->SetY(-10);
        // Set font
        $this->SetFont('dejavusans', 'I', 8);
        $foot = $datafromdb.'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages();

        $this->MultiCell(0, 10, $foot, 0, 'C');
    }
}

推荐答案

你可以添加一个 __construct 方法来传递你的数据.
试试这个:

you can add a __construct method to pass your data.
try this :

// my DB stuff here
$datafromdb = getDataFromDB();

class MYPDF extends TCPDF {
    private $datafromdb ;//<-- to save your data

    function __construct( $datafromdb , $orientation, $unit, $format ) 
    {
        parent::__construct( $orientation, $unit, $format, true, 'UTF-8', false );

        $this->datafromdb = $datafromdb ;
        //...
    }
    // Page footer
    public function Footer() {
        // Position at 10 mm from bottom
        $this->SetY(-10);
        // Set font
        $this->SetFont('dejavusans', 'I', 8);
        $foot = $this->datafromdb.'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages();

        $this->MultiCell(0, 10, $foot, 0, 'C');
    }
}

这篇关于如何使用从数据库中获取的数据在 TCPDF 中制作自定义动态页脚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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