Fpdf表在多个页面中

时间:2012-04-19 12:35:31

标签: php fpdf

我正在尝试使用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();
        }

它是我的函数的一部分,Generate table和$subjects是我从数据库获得的信息。

$subjects = array(array()) 

我无法理解为什么在第一页上常规的第二页和其他页面中不常见。我也检查页面的末尾。

1 个答案:

答案 0 :(得分:1)

这种情况正在发生,因为您在一个单元格中触发了页面中的分页符。

要么在fpdf中禁用“自动分页”,要么必须提前计算一行单元格的高度。

作为替代方案,您可以查看我的fpdf表脚本: http://interpid.eu/fpdf-table

相关问题