2013-11-27 183 views
2

我已经在Laravel 4FPDF页眉和页脚

我使用此代码尝试FPDF但功能安装FPDF Header()Footer()不工作

class PDF extends Fpdf 
{ 
    // Page header 
    function Header() 
    { 
     // Logo 
     $this->Image('logo.png',10,6,30); 

     // Arial bold 15 
     $this->SetFont('Arial','B',15); 

     // Move to the right 
     $this->Cell(80); 

     // Title 
     $this->Cell(30,10,'Title',1,0,'C'); 

     // Line break 
     $this->Ln(20); 

    } 

    // Page footer 
    function Footer() 
    { 
     // Position at 1.5 cm from bottom 
     $this->SetY(-15); 

     // Arial italic 8 
     $this->SetFont('Arial','I',8); 

     // Page number 
     $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C'); 
    } 
} 


// Instanciation of inherited class 

$pdf = new PDF(); 
$pdf->AliasNbPages(); 
$pdf->AddPage(); 
$pdf->SetFont('Times','',12); 

for($i=1;$i<=40;$i++) 
    $pdf->Cell(0,10,'Printing line number '.$i,0,1); 

$pdf->Output(); 
exit; 

这是结果:https://dl.dropboxusercontent.com/u/70804756/doc%20(3).pdf

有人能指出我哪里出错?

+0

你应该创建一个新的PDF实例,而不是FPDF。 –

+0

我改变了那部分,但没有工作。我看到如果我添加$ pdf-> Header();调用工作函数标题。在FPDF的文档有写:“这个例子使用的报头()和页脚()方法来处理页面的页眉和页脚他们被自动调用的,他们已经存在于FPDF类,但什么都不做,所以我们必须。扩展课程并覆盖它们。“ – chianta

回答

11

写延伸FPDF一个新的类,并把你的头&页脚方法在那里。

class PDF extends FPDF { 

    function Header() {} 
    function Footer() {} 
} 
在控制器

则...

new PDF();