FPDF/FPDI UseTemplate

2019-03-02 00:37发布

I'm using FPDI & FPDF to overlay new text on top of an existing PDF. It uses the useTemplate() method to achieve this.

Problem I'm having - it only applies the template to the first page. If the text is long, it will wrap to a second page, using the SetAutoPageBreak() method. How can I make it apply the template on every page?

标签: fpdf fpdi
1条回答
做自己的国王
2楼-- · 2019-03-02 01:13

I've cracked it. Looking into the code, I realised that even the SetAutoPageBreak() routine calls AddPage() internally, giving me the hook I needed to include my template on every page.

So, I extended the base FPDI class and over-rode the AddPage() method, including the useTemplate() stuff.

class BBPDF extends FPDI {
    function AddPage($orientation='', $size='') {
        parent::AddPage($orientation,$size);
        $this->setSourceFile('templates/discover-community.pdf');
        $template = $this->ImportPage(1);
        $this->useTemplate($template);
    }
}
查看更多
登录 后发表回答