fpdf分页符问题 [英] fpdf page break issue

查看:97
本文介绍了fpdf分页符问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个循环,可打印6行(多单元格)约30次.问题在于,当它到达底部页面时,它将打印多单元格中的2或3行,而在下一页时,它将打印其他3行.如果当前页上的所有6行没有足够的空间,我想使其在下一页上打印所有6行. 我使用以下代码:

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 next page it prints the other 3 rows. I want to make it print all 6 rows on the next page if there is not enough space for all 6 rows on the present page. I use this code:

$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
}

但是它不起作用.有什么办法吗?谢谢!

but it doesn't work. Any solutions? Thanks!

推荐答案

使用 GetY 要获取当前位置,请从文档高度中减去当前位置.如果该值小于多单元格高度的6倍(您有6行),请使用

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

这篇关于fpdf分页符问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆