3

I've created a PDF generator thanks to FPDF, it uses data from a mysql database and works very well. Number of pages is variable.

Then I wanted to add to every of this PDF some pages imported from other PDF files. Number of added page and adress of imported file are variable too.

It works very well, excepted that my Footer doesn't appear anymore. I want to keep this Footer on every page, the ones created by the generator and the ones imported. Can someone tell me where is the problem?..

This i my code :

require_once('gpdf/fpdf.php');
require_once('gpdf/fpdi.php');

class PDF extends FPDI
{

function Header()
{


}

function Footer()
{
    // Positionnement à 1,5 cm du bas
    $this->SetY(-15);
    // Police Arial italique 8
    $this->SetFont('Arial','I',8);
    // Numéro de page
    $this->Cell(0,10,'Devis from MyCompany - Page '.$this->PageNo().'/{nb}'.'        Paraphes :',0,0,'C');
}

}

// Instanciation de la classe dérivée



$pdf = new FPDI();
$pdf->AliasNbPages();

$pdf->AddPage();
    // Here is page 1, you don't need the details
$pdf->AddPage();
    // Here is page 2, some other pages can come too


// Then begins the importation

// get the page count
$pageCount = $pdf->setSourceFile('cgua/cgu_'.$customer['num'].'.pdf');
// iterate through all pages
for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
    // import a page
    $templateId = $pdf->importPage($pageNo);
    // get the size of the imported page
    $size = $pdf->getTemplateSize($templateId);

    // create a page (landscape or portrait depending on the imported page size)
    if ($size['w'] > $size['h']) {
        $pdf->AddPage('L', array($size['w'], $size['h']));
    } else {
        $pdf->AddPage('P', array($size['w'], $size['h']));
    }

    // use the imported page
    $pdf->useTemplate($templateId);
}


$pdf->Output('devis.pdf','I');

I've found no explanation about how to keep my Footer in FPDI's manual... I'm sure it's easy to rule the problem, I just didn't find the way!

Thanks!

lauxile
  • 31
  • 1
  • 3

1 Answers1

3

You created a new class that inherits the FPDI class. This new class, PDF, defines the Footer method correctly. But then you instantiated the FPDI class, instead of the PDF class.

Just change

$pdf = new FPDI();

to

$pdf = new PDF();

so that you can instantiate your new class and see the results of the new Footer method.

mckinzie25
  • 31
  • 5
  • With autload I have an error : "Fatal error: Class 'setasign\Fpdi' not found" Have you a solution ? Please – Rocstar Jul 12 '18 at 11:53
  • @Rocstar Not sure where "setasign" comes from without looking at your code, but you probably need to specify the full namespace for FPDI or use a "Use" statement. – mckinzie25 Jan 22 '19 at 20:34