Welcome Guest, Not a member yet? Register   Sign In
FPDF Header Footer Not Showing
#1

Hello all,
My controller code is:
PHP Code:
namespace App\Controllers;
use 
App\Libraries\FPDF;

class 
Test extends BaseController
{

 function 
Header()
 {
 
$this->Image('logo.png',90,15,36);
 
$this->SetFont('Arial','B',15);
 
$this->Cell(80);
 
$this->Cell(30,10,'Title',1,0,'C');
 
$this->Ln(20);
 }

 function 
Footer()
 {
 
$this->SetY(-15);
 
$this->SetFont('Arial','I',8);
 
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
 }

 public function 
index()
 {
 
$this->pdf = new fpdf();
 
$this->pdf->AliasNbPages();
 
$this->pdf->AddPage();
 
$this->pdf->SetFont('Times','',12);
 
$this->pdf->Image('logo.png',90,15,36);
 
$this->pdf->Cell(40,60,'Monthly Report');
 
$this->response->setHeader("Content-Type""application/pdf");
 
$this->pdf->Output("file.pdf"'I');
 }


How do you get the header and footer to work? Im on PHP 8.1.10 and CI 4.2.10
Reply
#2

Edited the code to: 
PHP Code:
namespace App\Controllers;
use 
App\Libraries\FPDF;

class 
TEST extends FPDF
{
 function 
Header()
 {
 
$this->Image('logo.png',10,6,30);
 
$this->SetFont('Arial','B',15);
 
$this->Cell(55);
 
$this->Cell(80,10,'MONTHLY REPORT',1,0,'C');
 
$this->Ln(20);
 }

 function 
Footer()
 {
 
$this->SetY(-15);
 
$this->SetFont('Arial','I',8);
 
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
 }
}

$test = new TEST();
$test->AliasNbPages();
$test->AddPage();
$test->SetFont('Times','',12);
for(
$i=1;$i<=40;$i++)
 
$test->Cell(0,10,'Printing line number '.$i,0,1);
$test->Output(); 

It's working now.
Reply
#3

Please edit your post topic title and add [SOLVED]

Thank you.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB