2013-10-01 40 views
1

我正在使用TCPDF供應商軟件包在CakePHP應用程序中生成PDF報告。 我必須在生成的PDF的每個頁面上創建頁面邊框。TCPDF - 所有頁面中的頁面邊框

我使用this solution來製作頁面邊框,但只能在生成的PDF的第一頁上繪製邊框。

我使用下面的代碼:

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 
$pdf->AddPage(); 

$pdf->SetLineStyle(array('width' => 15, 'color' => array(0,0,0))); 

$pdf->Line(0,0,$pdf->getPageWidth(),0); 
$pdf->Line($pdf->getPageWidth(),0,$pdf->getPageWidth(),$pdf->getPageHeight()); 
$pdf->Line(0,$pdf->getPageHeight(),$pdf->getPageWidth(),$pdf->getPageHeight()); 
$pdf->Line(0,0,0,$pdf->getPageHeight()); 

//rest of my code to make proper Html 
..... 
..... 

$pdf->writeHTML($content_html, true, 0, true, 0); //$content_html contains the whole Html which outputs me several PDF pages 

ob_clean(); 
$pdf_status = $pdf->Output($directory_path.$file_name.EXT_PDF, 'F'); // save pdf on the given path 

請建議的解決方案。任何幫助,將不勝感激。

+0

通過你是它的外觀在頁面1上繪製邊框,然後編寫多頁HTML。您不會在任何地方告訴它在其餘頁面上寫入邊框。我不相信這是可能的。 –

+0

@MichaelDeMutis,是的,我想要如何在其餘頁面上書寫邊框。 –

回答

3

以下是我用於在生成的pdf中的所有頁面上創建頁邊空白邊框的技巧。

  1. Create a new class extend from TCPDF class
  2. Override the Header method.(該方法將被調用每一個新的pdfpage代)

請看代碼如下:

<?php 
App::import('Vendor','tcpdf/tcpdf'); 
App::import('Vendor','tcpdf/config/lang/eng'); 
class AUTHPDF extends TCPDF 
{ 
    protected $processId = 0; 
    protected $header = ''; 
    protected $footer = ''; 
    static $errorMsg = ''; 

    /** 
     * This method is used to override the parent class method. 
    **/ 
    public function Header() 
    { 
     $this->writeHTMLCell($w='', $h='', $x='', $y='', $this->header, $border=0, $ln=0, $fill=0, $reseth=true, $align='L', $autopadding=true); 
     $this->SetLineStyle(array('width' => 0.40, 'color' => array(153, 204, 0))); 

     $this->Line(5, 5, $this->getPageWidth()-5, 5); 

     $this->Line($this->getPageWidth()-5, 5, $this->getPageWidth()-5, $this->getPageHeight()-5); 
     $this->Line(5, $this->getPageHeight()-5, $this->getPageWidth()-5, $this->getPageHeight()-5); 
     $this->Line(5, 5, 5, $this->getPageHeight()-5); 
    } 
}