FPDF跳过第一行
问题描述:
我写了一个简单的FPDF代码,但我遇到了一个问题。FPDF跳过第一行
由于某些原因,for循环跳过第一行(单元格1,单元格2,单元格3)。
代码:
<?php
require('temp/fpdf.php');
class PDF extends FPDF
{
function Header(){
$this->SetY(0);
$this->SetFont('Arial','I',8);
$this->Cell(0,5,'Page '.$this->PageNo(),0,0,'C');
}
function Footer(){
$this->SetY(-5);
$this->SetFont('Arial','I',8);
$this->Cell(0,5,'Page '.$this->PageNo(),0,0,'C');
}
}
$pdf = new PDF();
$pdf->SetMargins(0,0,0);
$pdf->AddPage();
$pdf->SetFont('Times','',12);
for($i=0;$i<=24;$i++){
$pdf->Cell(70,30,'Printing line number '.$i,0,0,'C');
if(($i%3==0)&&($i!=0)){
$pdf->Ln();
}
}
$pdf->Output();
?>
我盯着几个小时的代码,但我无法找到答案,所以任何帮助表示赞赏。
答
你的第一个集打印浮动到右侧。作为一个快速修复尝试添加添加换行符并清除PDF定义中不需要的浮动。
添加
$pdf->Ln();
后
$pdf->AddPage();
答
我看到两种可能性,你可能想检查。首先是边距全部为零,但为了使PDF能够正确打印或保存,它们需要在侧面上为1“上/下和0.5”。你也必须考虑到你的循环$ i的第一次迭代将等于0,并且你的第一个单元格会打印出0而不是1.让我知道如果这不能平移,我可以帮助更多。我实际上处于一个庞大的FPDF项目中,并且发现了许多细微差别。
我只注意到这一点:
if(($i%3==0)&&($i!=0)){
$pdf->Ln();
}
使用此http://calculator.sdsu.edu/calculator.php使用$ I值来计算模量,你会看到0%3 = 0,1%3 = 4,2%3 = 5 。这将跳过你的第一行。
我个人已经写这样的:
$i = 1;
while($i <=25)
{
$pdf->Cell(70,30,'Printing line number '.$i,0,0,'C');
if(($i % 3) == 0)
{
$pdf->Ln();
}
}
作品,谢谢。 – Vucko 2013-04-29 20:16:01