0

The problem is, I need to write data to several copies of the same imported pdf file, and save it as one pdf. I can write data to one page just fine, but when I try to write to more than one, or even continue text (using SetAutoPageBreak()), it simply stops writing once it hits the next page. Although, if I add an arbitrary loop to write more data, the resulting pdf's number of pages is increased to accommodate the added data, but the pages beyond the first are still blank. I have simplified what I'm trying to do into a smaller example to illustrate the issue:

public function actionSample() {
    $pdf = new FPDI();
    $pdf->AcceptPageBreak();
    $pdf->SetAutoPageBreak(true, 30);
    $pagecount = $pdf->setSourceFile('images/sample.pdf');
    for ($i = 1; $i <= $pagecount; $i++) {
        $pdf->AddPage();
        $tplidx = $pdf->ImportPage($i);
        $pdf->useTemplate($tplidx, 10, 10, 200);
        $s = $pdf->getTemplatesize($tplidx);
        $pdf->SetTextColor(32,32,32);
        $pdf->SetFontSize(10);
        $pdf->SetXY($pdf->getX(), $pdf->getY()+10);
        $pdf->Write(2, 'This is not!');
    }

    $pdf->Output('Sample.pdf', 'D');
}

The sample document has 3 blank pages initially. (I did this to make it easier to see what was being written)

Rudi Visser
  • 21,350
  • 5
  • 71
  • 97

1 Answers1

6
$pdf->AddPage();

you have to just put this piece of code inside for loop near closing braces.

All the best..!!

Tobia Zambon
  • 7,479
  • 3
  • 37
  • 69
Miral Viroja
  • 333
  • 2
  • 10