Home » Php » FPDF – Other ways to call Header and Footer with Codeigniter controller

FPDF – Other ways to call Header and Footer with Codeigniter controller

Posted by: admin June 30, 2018 Leave a comment

Questions:

I am new to FPDF and I am trying to make the header and footer change,
when I used

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

It has error that says

‘Cannot redeclare header()’,

so what Im asking is, is there any other way of calling the header and footer? like

$pdf->header->SetFont('Arial','B',15)

or something?

Here is my code, I copied it from the tutorial 2 of FPDF, I dont want it views, I wanted it in the controller so it can called all the time

public function tutorial2()
{
    $this->load->library('myfpdf'); 
    // function Header()
    // {
    //     $this->SetFont('Arial','B',15);
    //     $this->Cell(80);
    //     $this->Cell(30,10,'Title',1,0,'C');
    //     $this->Ln(20);
    // } -- the Header function that is normally used

    $pdf = new FPDF();
    $pdf->AliasNbPages();
    $pdf->AddPage();
    $pdf->SetFont('Times','',12);
    //$pdf->footer->SetY(-15);
    //$pdf->footer->SetFont('Arial','I',8);
    //$pdf->footer->Cell(0,10,'Page '.$pdf->footer->PageNo().'/{nb}',0,0,'C');      -- not actually a working, or is there another way?
    for($i=1;$i<=40;$i++)
        $pdf->Cell(0,10,'Printing line number '.$i,0,1);
    $pdf->Output();     
}
Answers: