I am trying to create an invoice document and display the items in pdf.
The problem I have is that the first page will use a pdf template(Using FPDI) that has the Company logo, company information and the list of items bought.
If the list of items will require more than one page, the next pages will need to use second page of pdf template that only shows the company logo as a header and the continuation of the items bought. Below is my sample code. I also tried to extend the fpdi based on this SO post but I cant make it work.
$pdf = new FPDI();
ob_start();
echo $this->view->print_invoice($productItems, $customerInfo);
$content = ob_get_contents();
ob_clean();
// add a page
$pdf->addPage();
$pdf->writeHTML($content);
$pageCount = $pdf->setSourceFile(ROOT_DIR . "public/pdf-templates/group.pdf");
$tplIdx = $pdf->importPage(1, '/MediaBox');
$pdf->useTemplate($tplIdx, 10, 10, 190, 280);
$pdf->Output('outfile.pdf','I');
Thanks in advance for your help!
Just implement the logic you describe in a header() method of an extending class:
class PDF extends FPDI
{
public function Header()
{
if ($this->PageNo() > 1) {
$tplIdx = $this->importPage(2);
} else {
$tplIdx = $this->importPage(1);
}
$this->useTemplate($tplIdx);
}
}
ob_start();
echo $this->view->print_invoice($productItems, $customerInfo);
$content = ob_get_contents();
ob_clean();
$pdf = new PDF();
$pdf->setSourceFile(ROOT_DIR . "public/pdf-templates/group.pdf");
$pdf->addPage();
$pdf->writeHTML($content);
$pdf->Output('outfile.pdf','I');