PHP FPDF 当 Y 到达 foreach 中的某个点时添加新页面
我在FPDF中有以下代码:
foreach($dataas $data){
$this->setFont('Arial','', 7);
$this->SetY(105);
$y = $this->GetY();
$valY += 10;
$b = $y + $valY;
$pageH = $this->getPageHeight();
if($b > 200){
$this->AddPage();
$b = 10;
}
$this->SetXY(5,$b);
$this->MultiCell($w[0],3,$sum++,0,'L');
$this->SetXY(17,$b);
$this->MultiCell($w[1],3,$data['data1'],0,'L');
$this->SetXY(50,$b);
$this->MultiCell($w[2],3,$data['data2'],0,'C');
$this->SetXY(65,$b);
$this->MultiCell($w[3],3,$data['data3'],0,'C');
$this->SetXY(82,$b);
$this->MultiCell($w[4],3,$data['data4'],0,'C');
$this->SetXY(97,$b);
$this->MultiCell($w[5],3,$data['data5'],0,'C');
$this->SetXY(114,$b);
$this->MultiCell($w[6],3,$data['data6'],0,'L');
$this->SetXY(125,$b);
$this->MultiCell($w[7],3,number_format($data['data7'],2,".",","),0,'L');
$this->SetXY(143,$b);
$this->MultiCell($w[8],3,number_format($data['data8'],2,".",","),0,'L');
$this->SetXY(161,$b);
$this->MultiCell($w[9],3,number_format($data['data9'],2,".",","),0,'L');
$this->SetXY(186,$b);
$this->MultiCell($w[10],3,number_format($data['data10'],2,".",","),0,'L');
$this->SetXY(204,$b);
$this->MultiCell($w[11],3,number_format($data['data11'],2,".",","),0,'L');
$this->SetXY(222,$b);
$this->MultiCell($w[12],3,number_format($data['data12'],2,".",","),0,'L');
$this->SetXY(247,$b);
$this->MultiCell($w[13],3,number_format($$data['data13'],2,".",","),0,'L');
$this->SetXY(272,$b);
$this->MultiCell($w[14],3,$data['data14'],0,'L');
$this->SetAutoPageBreak(false);
}
这就是我得到的:
第1页
- 1
- 2 3
- 4
- 5
- 第
2
- 页6
第3页
- 7
第4页
- 8
但我想要这样的东西:
第1页:
- 1
- 2
- 3
- 4
- 5
第2页:
- 6
- 7
- 8
- 9
- 10
每当 Y 的值达到 200 时,它就会添加一个新页面,并将新页面上的 Y 重置回 10,但 Y 值外部 IF 没有更改为 10,我需要 foreach 来循环数据。 我怎样才能像上面那样将 IF 之外的 Y 设置为 10 ? 提前致谢!
i have the following codes in FPDF :
foreach($dataas $data){
$this->setFont('Arial','', 7);
$this->SetY(105);
$y = $this->GetY();
$valY += 10;
$b = $y + $valY;
$pageH = $this->getPageHeight();
if($b > 200){
$this->AddPage();
$b = 10;
}
$this->SetXY(5,$b);
$this->MultiCell($w[0],3,$sum++,0,'L');
$this->SetXY(17,$b);
$this->MultiCell($w[1],3,$data['data1'],0,'L');
$this->SetXY(50,$b);
$this->MultiCell($w[2],3,$data['data2'],0,'C');
$this->SetXY(65,$b);
$this->MultiCell($w[3],3,$data['data3'],0,'C');
$this->SetXY(82,$b);
$this->MultiCell($w[4],3,$data['data4'],0,'C');
$this->SetXY(97,$b);
$this->MultiCell($w[5],3,$data['data5'],0,'C');
$this->SetXY(114,$b);
$this->MultiCell($w[6],3,$data['data6'],0,'L');
$this->SetXY(125,$b);
$this->MultiCell($w[7],3,number_format($data['data7'],2,".",","),0,'L');
$this->SetXY(143,$b);
$this->MultiCell($w[8],3,number_format($data['data8'],2,".",","),0,'L');
$this->SetXY(161,$b);
$this->MultiCell($w[9],3,number_format($data['data9'],2,".",","),0,'L');
$this->SetXY(186,$b);
$this->MultiCell($w[10],3,number_format($data['data10'],2,".",","),0,'L');
$this->SetXY(204,$b);
$this->MultiCell($w[11],3,number_format($data['data11'],2,".",","),0,'L');
$this->SetXY(222,$b);
$this->MultiCell($w[12],3,number_format($data['data12'],2,".",","),0,'L');
$this->SetXY(247,$b);
$this->MultiCell($w[13],3,number_format($data['data13'],2,".",","),0,'L');
$this->SetXY(272,$b);
$this->MultiCell($w[14],3,$data['data14'],0,'L');
$this->SetAutoPageBreak(false);
}
this is what i get :
page 1
- 1
- 2
- 3
- 4
- 5
page 2
- 6
page 3
- 7
page 4
- 8
but instead i want something like this:
page 1:
- 1
- 2
- 3
- 4
- 5
page 2:
- 6
- 7
- 8
- 9
- 10
everytime the value of Y hit 200, it adds a new page and also reset the Y on the new page back to 10 but the Y value outside IF didnt change to 10 and i need the foreach to loop the data.
how do i make Y outside IF set to 10 like the above?
thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论