Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple pages #151

Closed
Maniraj-Webner opened this issue May 17, 2022 · 1 comment
Closed

Multiple pages #151

Maniraj-Webner opened this issue May 17, 2022 · 1 comment

Comments

@Maniraj-Webner
Copy link

I'm trying to add data to multiple pages, but it overwrites the data of another page.
Here is my code

$pdf = new \setasign\Fpdi\Fpdi();
$pdf->AddPage();
$pageCount = $pdf->setSourceFile('sample.pdf');

    for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
        // import a page
        $templateId = $pdf->importPage($pageNo);
        // get the size of the imported page
        $size = $pdf->getTemplateSize($templateId);
        // use the imported page
        $pdf->useTemplate($templateId);
  
        $pdf->SetFont('Helvetica');
        if($pageNo == 1){
            $pdf->SetXY(15, 15);
            $pdf->Write(8, 'A complete document imported with FPDI page1');
        }
        else if($pageNo == 2){
            $pdf->SetXY(20, 20);
            $pdf->Write(8, 'A complete document imported with FPDI page2');
       }
        
    }
    dd($pdf->Output());
@JanSlabon
Copy link
Member

Simply move the $pdf->AddPage() call into the for-loop.
Actually you don't use $size. If this is intentionally you can remove the line, otherwise use it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants