我正在尝试使用 fPDF 和 PHP 构建一个 PDF 表,如果它适合一页,它会创建一个表。但是,如果表格不适合一页,虽然第一页很好,但在第二页和其他页面上,表格不规则。这是我的 pdf 输出的示例:
https://rapidshare.com/files/486723233/results.pdf
这是我创建此表的代码:
//FILL THE TABLE
$max_number_of_lines = 0;
for ($index = 0; $index < count($subjects); $index++,$temp=0,$row_height = 15,$max_number_of_lines = 0) {
//Account height of row, all will be same
//Issue a page break first if needed
if($this->GetY()+$row_height > $this->PageBreakTrigger)
$this->AddPage($this->CurOrientation);
foreach ($subjects[$index] as $fields) {
$myString = mb_convert_encoding($fields, "iso-8859-9", "auto");
$number_of_lines = ceil(($this->GetStringWidth($fields))/$fieldLengthArray[$temp]);
if ($row_height < ceil($number_of_lines * 15)) {
$row_height = ceil($number_of_lines * 15);
$max_number_of_lines = $number_of_lines+1;
}
$temp++;
}
$temp=0;
foreach ($subjects[$index] as $myFields) {
//$this->SetAutoPageBreak(true,$row_height);
$this->SetY($currentY);
$this->SetX($currentX);
$myString = mb_convert_encoding($myFields, "iso-8859-9", "auto");
$number_of_lines = ceil(($this->GetStringWidth($myFields))/$fieldLengthArray[$temp]);
if ($number_of_lines < $max_number_of_lines-1) {
$this->Rect($currentX, $currentY, $fieldLengthArray[$temp], $row_height);
//Draw the border
//$this->Rect($x, $y, $w, $h);
$this->MultiCell($fieldLengthArray[$temp], ceil($row_height/$max_number_of_lines) ,
$myString,0, 'L', $fill);
}
else {
//Draw the border
//$this->Rect($x, $y, $w, $h);
$this->Rect($currentX, $currentY, $fieldLengthArray[$temp], $row_height);
$this->MultiCell($fieldLengthArray[$temp], ceil($row_height/$max_number_of_lines),
$myString,0, 'L', $fill);
}
$currentX += $fieldLengthArray[$temp];
$temp++;
//$this->Ln();
}
$this->Ln($row_height);
$this->SetY($currentY);
$currentX = $this->GetX();
$currentY += $row_height;
}
$this->SetFillColor(238);
$this->SetLineWidth(0.2);
$this->SetFont('arial_tr', '', 10);
$this->Ln();
}
它是我的功能的一部分,生成表,$subjects
是我从数据库中获得的信息。
$subjects = array(array())
我不明白为什么它在第二页和其他页面上不规则,而在第一页上是规则的。我还检查页面的结尾。