2012-09-10 31 views
6

我有这个循环打印6行(多单元)约30次。问题是,当它到达底部页面时,它从多单元打印2或3行,并在下一页打印其他3行。如果当前页面上的所有6行没有足够的空间,我想让它在下一页上打印所有6行。我使用此代码:fpdf分页问题

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

但它不起作用。任何解决方案谢谢!

回答

19

使用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(); 
?> 
+0

嗨,我修改了这样的代码,但它什么也没做。你在某处看到错误吗? –

+0

我想通了。它正在工作。 –

+0

GReat - 只是编辑我的答案以进一步提供帮助:) – Mark