Rectangle 27 0

php fpdf page break issue?


<?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();
?>

Because it was useful to me note that for A4 $page_height = 297;

Hi, I modified the code like that, but it does nothing. Do you see an error somewhere?

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

SetAutoPageBreak(boolean auto , float margin) fx helped me.The second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.

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.

Note
Rectangle 27 0

php fpdf page break issue?


<?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();
?>

Because it was useful to me note that for A4 $page_height = 297;

Hi, I modified the code like that, but it does nothing. Do you see an error somewhere?

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

SetAutoPageBreak(boolean auto , float margin) fx helped me.The second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.

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.

Yes absolutely @Ravs, that would be the typical application. The OP here wanted to make sure all 6 rows would fit, just using the autopagebreak would break his tables up if 1-5 rows would fit on the page, which is why he needed a more elaborate solution.

Note
Rectangle 27 0

php fpdf page break issue?


<?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();
?>

Because it was useful to me note that for A4 $page_height = 297;

Hi, I modified the code like that, but it does nothing. Do you see an error somewhere?

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

SetAutoPageBreak(boolean auto , float margin) fx helped me.The second parameter is the distance from the bottom of the page that defines the triggering limit. By default, the mode is on and the margin is 2 cm.

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.

Yes absolutely @Ravs, that would be the typical application. The OP here wanted to make sure all 6 rows would fit, just using the autopagebreak would break his tables up if 1-5 rows would fit on the page, which is why he needed a more elaborate solution.

Note