1

I have this code below which works perfectly for me, the problem is the first page is not numbered and then the footer that i have set appears as the header, suggestions

      $full_name = 'custom_worksheets/' . $sheet_name . '.pdf';

        $pdf = new FPDI('P', 'mm', 'A4');
        $pdf->AliasNbPages();
        $pdf->AddPage();
        // set the sourcefile
        $pages_count = $pdf->setSourceFile($full_name);


        for ($i = 1; $i <= $pages_count; $i++) {
            //$pdf->AddPage(); 

            $tplIdx = $pdf->importPage($i);
    // Go to 1.5 cm from bottom
            $pdf->SetY(-31);
            // Select Arial italic 8
            $pdf->SetFont('Arial', 'I', 8);
            // Print centered page number
            $pdf->Cell(0, 10, 'Page ' . $pdf->PageNo() . ' of {nb}', 0, 0, 'C');
            $pdf->Cell(0, 10, date('d/m/Y'), 0, 0, 'R');
            $pdf->Cell(0, 0,$labref . '/' . ucfirst(str_replace('_', ' ', $sheet_name)) . ' / Download x : author - ' . $full_names,0,0);

            $pdf->useTemplate($tplIdx);




        }


       // Output
        $pdf->Output('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf', 'D');

        redirect('generated_custom_sheets/' . $labref . '_' . $sheet_name . '.pdf');
alphy
  • 291
  • 3
  • 19

1 Answers1

0

Your footer text is likely wrapping or expanding due to its height onto the next page. Try moving this text up by increasing the offset to something like -30:

$pdf->SetY(-30);

That can help rule out the text going to the next page. It's possible your pdf has already wrapped to the next page so you can move this footer drawing logic up above your template, so that the footer is drawn first, then have your template SetY to the top of the page to write itself. I always draw my footers and headers first, then the content of my pdf pages.

I'd also recommend you switch from the Write to a Cell since Write is a free flowing text object.

Scott
  • 3,736
  • 2
  • 26
  • 44