Php FPDI,FPDF SetAutoPageBreak在中断后将模板添加到页面
我已经创建了一个表单,允许用户创建一个具有无限页面数的pdf,我已经设置了SetAutoPageBreak,以便它继续到第二个页面,但是我无法让在分页符后创建的页面继续使用原始模板文件。基本代码如下所示Php FPDI,FPDF SetAutoPageBreak在中断后将模板添加到页面,php,fpdf,fpdi,Php,Fpdf,Fpdi,我已经创建了一个表单,允许用户创建一个具有无限页面数的pdf,我已经设置了SetAutoPageBreak,以便它继续到第二个页面,但是我无法让在分页符后创建的页面继续使用原始模板文件。基本代码如下所示 require('fpdf.php'); require('fpdi.php'); $pdf = new FPDI('P','mm','A4'); $pageCount = $pdf->setSourceFile("source_file.pdf"); $tplIdx
require('fpdf.php');
require('fpdi.php');
$pdf = new FPDI('P','mm','A4');
$pageCount = $pdf->setSourceFile("source_file.pdf");
$tplIdx = $pdf->importPage(1);
$pdf->AddPage();
$pdf->useTemplate($tplIdx);
$pdf->SetTextColor(63,76,89);
$pdf->SetMargins(5,39,5,20);
$pdf->SetAutoPageBreak(true,22); //page created doesn't have template attached
$pdf->SetDrawColor(225,225,225);
$pdf->SetFillColor(248,248,248);
$pdf->SetLineWidth(1);
$pdf->SetXY(82, 40);
$pdf->MultiCell(165,5,$company.$block,0,L,false);
$pdf->SetXY(19, 45);
$pdf->MultiCell(165,5,$date.$block,0,L,false);
$pdf->Output();
环顾四周,这个问题是我能找到的最接近的问题,但我不确定它是否相关:
谢谢只需将导入的页面放在页眉方法中:
class PDF extends FPDI
{
protected $_tplIdx;
public function Header()
{
if (null === $this->_tplIdx) {
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
}
$pdf = new PDF('P','mm','A4');
$pdf->AddPage();
...
…一切都应该按预期进行。除了@JanSlabon的回答外:(我没有必要的声誉来写评论,所以我会在这里发布,希望没问题) 如果您只想在第一个页面使用某个模板,而在所有其他页面上使用另一个模板,则可以按如下操作:
class PDF extends FPDI
{
protected $_tplIdx;
public function Header()
{
if (null === $this->_tplIdx) {
$this->setSourceFile('paper1.pdf');
$this->_tplIdx = $this->importPage(1);
} else {
$this->setSourceFile('paper2.pdf');
$this->_tplIdx = $this->importPage(1);
}
$this->useTemplate($this->_tplIdx);
}
}
我知道这并不完全是@Searlee想要的,但也许它能帮助其他人