fpdf € transform into ? with UTF-8

You try to write a € character on your pdf doc but it is transformed into a “?”.
You can replace it by the chr(128) sign.

$this->MultiCell(170, $this->hh, $price." ".chr(128), 0, 'L', false);

When the sign is inside a string, you can use this

$contenu = str_replace('€', chr(128), $contenu);
$this->MultiCell(170, $this->hh, $contenu, 0, 'L', false);

But you have special characters too, you need to encode string into UTF-8

$contenu = str_replace('€', chr(128), $contenu);
$this->MultiCell(170, $this->hh, utf8_decode($contenu), 0, 'L', false);

This works well for “é” or “ç” but not for “€”.
The ultimate solution is :

$contenu = str_replace('€', utf8_encode(chr(128)), $contenu);
$this->MultiCell(170, $this->hh, utf8_decode($contenu), 0, 'L', false);

fpdf import pdf file

You are using fpdf to generate PDF file in php. You want to use an existing PDF file to import header and footer ? This is easy :

First, download FPDI lib here

and do that on your code :

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

$pdf = new FPDI();   // FPDI and not FPDF
$pdf->AliasNbPages();
$pdf->AddPage();
$pagecount = $pdf->setSourceFile(SF_ROOT_DIR.'/lib/fpdf/courrier.pdf');
$tplix = $pdf->importPage(1);
$pdf->useTemplate($tplix);
$pdf->Output('newdocument.pdf', 'D'); 

If you get this error

Warning: require_once(fpdf_tpl.php): failed to open stream:

you need to get the FPDF_TPL class too.

This only import file for the first page, if you want it on every page, override AddPage() function :

public function AddPage($orientation='', $size='', $keepmargins=false, $tocpage=false)
{
    parent::AddPage();
    $pagecount = $this->setSourceFile(SF_ROOT_DIR.'/lib/fpdf/courrier.pdf');                                                          
    $tplix = $this->importPage(1);
    $this->useTemplate($tplix);
}

fpdf add page number

Here an easy way to add page number at the end of a fpdf document

In your fpdf class, before calling addpage(), call the AliasNbPages() fonction

$this->AliasNbPages();

then create a footer() fonction to override the default empty footer

function Footer()
{
        $this->SetY(-10);
        $this->SetFont('Arial', '', 8);
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}', 0, 0, 'C');
        $this->SetY(-10);
        $this->Cell(0,10,"date d'impression: ".date('d/m/Y'), 0, 0, 'R');
}

The complete class : file pdfListeDemandes.class.php

<?php

class pdfListeDemandes extends FPDF
{
   function init()
   {
                $this->AliasNbPages();
                ...
   }
   function writeListe()
   {
         $this->init();
         ...
   }

   function Footer()
   {
        $this->SetY(-10);
        $this->SetFont('Arial', '', 8);
        $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}', 0, 0, 'C');
        $this->SetY(-10);
        $this->Cell(0,10,"date d'impression: ".date('d/m/Y'), 0, 0, 'R');
   }

}

And the code to call your class

$pdf = new pdfListeDemandes();
$pdf->writeListe();
$pdf->output('Liste_demande.pdf', 'D');
exit;