我有一个循环打印 6 行(多单元格)约 30 次。问题是,当它到达底部页面时,它会打印多单元格中的 2 或 3 行,并在下一页上打印其他 3 行。如果当前页面上没有足够的空间容纳所有 6 行,我想让它在下一页上打印所有 6 行。
我使用这段代码:
$height_of_cell = 60; mm
$page_height = 279.4; // mm (portrait letter)
$bottom_margin = 20; // mm
$space_left = $page_height - $p->GetY(); // space left on page
$space_left -= $bottom_margin; // less the bottom margin
if ( $height_of_cell >= $space_left) {
$p->Ln();
$p->AddPage(); // page break
$p->Cell(100,5,'','B',2); // this creates a blank row for formatting reasons
}
但它不起作用。有什么解决办法吗?谢谢!
Use GetY要获取当前位置,请从文档的高度中减去它。如果该值小于多单元格高度的 6 倍(您有 6 行),则使用以下命令强制分页AddPage.
我知道你解决了这个问题,但为了其他人的利益,这应该给出一个广泛的想法。
<?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();
?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)