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 :


$pdf = new FPDI();   // FPDI and not FPDF
$pagecount = $pdf->setSourceFile(SF_ROOT_DIR.'/lib/fpdf/courrier.pdf');
$tplix = $pdf->importPage(1);
$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)
    $pagecount = $this->setSourceFile(SF_ROOT_DIR.'/lib/fpdf/courrier.pdf');                                                          
    $tplix = $this->importPage(1);

Leave a Reply