【发布时间】:2019-09-26 13:56:51
【问题描述】:
我正在尝试使用 multiCell 显示数据。而当页面中的数据到达 y=228 时,我希望它转到下一个 Page 并显示在 y=112 的位置。
作为第一步,我尝试只添加 2 个简单条件:
当数据到达位置 y=228 时创建一个新页面 当数据转到下一页时,在位置 =112 处显示结果
成功了。但是如果当前的 multiCell 内容很大,它不会转到下一页,直到它完成写入所有 multicell 内容,所以我添加了函数 SetAutoPageBreak 所以它在 y=228 时插入一个分页符。
问题从这里开始代码没有将我的数据插入新页面中我定义的位置(y = 112)它插入到开始。我不知道如何解决这个问题我希望我能找到一些帮助我会很感激的。
这是我的代码:
<?php
require ('../fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 12);
$y = $pdf->GetY();
$x = $pdf->GetX();
$width_cell = array(
10,
30,
50
);
$pdf->SetFillColor(193, 229, 252);
$pdf->SetY(112);
$pdf->Cell($width_cell[0], 10, 'ID', 1, 0, C, true);
$pdf->Cell($width_cell[1], 10, 'NAME', 1, 0, C, true);
$pdf->Cell($width_cell[2], 10, 'CLASS', 1, 1, C, true);
$pdf->SetFont('Arial', '', 10);
for ($i = 0;$i < 30; $i++) {
$pdf->Cell($width_cell[0], 10, $i, 1, 0, C, false);
$pdf->Cell($width_cell[1], 10, 'John Deo', 1, 0, C, false);
$pdf->Cell($width_cell[2], 10, 'Four', 1, 1, C, false);
$y = $pdf->GetY();
$pdf->Cell($width_cell[0], 10, $i, 1, 0, C, false);
$pdf->Cell($width_cell[1], 10, 'Y:' . $y, 1, 0, C, false);
// $pdf->Cell($width_cell[2],10,'Four',1, 1, C, false);
$pdf->MultiCell($width_cell[2], 10, 'four four four four four four four four four four four four four four four four four four four four four four ', 1, C, false);
// Uncomment this line to see what Happends when the Page Break is inserted
// $pdf->SetAutoPageBreak(auto,69);
$y = $pdf->GetY();
if ($y > 228 && $i != 29) {
$pdf->AddPage();
$pdf->SetY(112);
}
/*
if ($pdf->PageNo() != 1 && $y < 20){
$pdf->SetY(112);
}
*/
}
$pdf->Output();
?>
【问题讨论】: