FPDF/FPDI使用模板 [英] FPDF/FPDI UseTemplate
问题描述
我正在使用FPDI& FPDF将新文本覆盖在现有PDF的顶部.它使用useTemplate()方法来实现这一点.
I'm using FPDI & FPDF to overlay new text on top of an existing PDF. It uses the useTemplate() method to achieve this.
我遇到的问题-它仅将模板应用于首页.如果文本较长,则将使用SetAutoPageBreak()方法将其换行到第二页.如何使它在每个页面上应用模板?
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?
推荐答案
我已经破解了.通过查看代码,我意识到即使SetAutoPageBreak()例程也在内部调用AddPage(),这给了我在每个页面上包含我的模板所需的钩子.
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.
因此,我扩展了FPDI基类并覆盖了AddPage()方法,包括useTemplate()东西.
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);
}
}
这篇关于FPDF/FPDI使用模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!