fpdf page break issue

后端 未结 1 392
长发绾君心
长发绾君心 2021-01-05 10:55

I have this loop that prints 6 rows (multicell) for about 30 times. The issue is that when it reaches the bottom page it prints 2 or 3 rows from the multicell and on the nex

相关标签:
1条回答
  • 2021-01-05 11:02

    Use GetY to get the current position, subtract it from the height of your document. If that is less than 6x (you have 6 rows) your multicell height, then force a page break by using AddPage.

    I know you fixed this, but for the benefit of anyone else, this should give a broad idea.

    <?php
    $p = new FPDF();
    $p->AddPage();
    $p->SetFont('Arial','B',16);
    $p->SetAutoPageBreak(false);
    $height_of_cell = 60; // mm
    $page_height = 286.93; // mm (portrait letter)
    $bottom_margin = 0; // mm
      for($i=0;$i<=100;$i++) :
        $block=floor($i/6);
        $space_left=$page_height-($p->GetY()+$bottom_margin); // space left on page
          if ($i/6==floor($i/6) && $height_of_cell > $space_left) {
            $p->AddPage(); // page break
          }
        $p->Cell(100,10,'This is a text line - Group '.$block,'B',2);
      endfor;
    $p->Output();
    ?>
    
    0 讨论(0)
提交回复
热议问题