2

I am creating a pdf document using tcpdf which is going well. The issue I am having is that I want to include an external pdf in the middle of the document and then continue to add my own pages afterwards.

I have read that FPDI is the best way to achieve this but I am stuck with trying to implement a solution. All of the examples I have found seem to revolve around using an external pdf as a background or template to the entire document, not just as an insert into a document.

Any help would be gratefully received.

1 Answers1

0

AddPage() Method generates a blank page. Each call generates only 1 page. You need to call AddPage() before useTemplate(); After that you can still add new context.

$pdf = new FPDI();
$pdf->AddPage();
$pdf->AddFont('courier');
$pdf->Write(10, 'page 1 created by TCPDF');
$pages = $pdf->setSourceFile('middle.pdf');
for($i=0; $i<$pages; $i++)
{
     $pdf->AddPage();
     $tplIdx = $pdf->importPage($i+1);
     $pdf->useTemplate($tplIdx, 10, 10, 200);
}
$pdf->AddPage();
$pdf->Write(10, 'page 2 created by TCPDF');
mirushaki
  • 897
  • 1
  • 10
  • 13