2014-09-02 100 views
0

我創建了一個表單,允許用戶創建一個具有無限數量的頁面的PDF,我已經設置了SetAutoPageBreak,以便它繼續到第二個頁面上,但是我無法獲取分頁符後創建的頁面以繼續使用原始模板文件。基本代碼可以在下面看到。FPDI,FPDF SetAutoPageBreak中斷後頁面添加模板

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

說完看了看周圍,這個問題是我能找到但我不知道它是否是相關最接近的:FPDF/FPDI UseTemplate

感謝

回答

0

只需將導入的頁面的頁眉方法:

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(); 
... 

...一切都應按預期工作。