2012-08-24 58 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); 
    } 
}