1

我正在使用 FPDI 和 FPDF 将新文本覆盖在现有 PDF 之上。它使用 useTemplate() 方法来实现这一点。

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

4

1 回答 1

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);
    }
}
于 2012-08-28T08:48:37.593 回答