2012-08-24 65 views
1

我正在使用FPDI & FPDF覆盖现有PDF上的新文本。它使用useTemplate()方法来实现这一点。FPDF/FPDI使用模板

问题我有 - 它只将模板应用到第一页。如果文本很长,则使用SetAutoPageBreak()方法将其换行到第二页。我怎样才能使它在每个页面上应用模板?

回答

5

我已经破解了它。纵观代码,我意识到即使是SetAutoPageBreak()例程在内部调用了AddPage(),也给了我需要在每个页面上包含我的模板的钩子。

因此,我扩展了基本的FPDI类并重载了AddPage()方法,包括useTemplate()的东西。

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); 
    } 
}