2012-04-19 58 views
0

我想用fPDF和PHP構建一個PDF表,如果它適合一個頁面,它將創建一個表。但是,如果表格不適合放在一個頁面中,儘管第一頁是好的,但在第二頁和其他頁面上,表格並不規則。這裏是我的PDF輸出的一個例子:Fpdf表在多個頁面

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()) 

我不明白爲什麼它不是第二頁和其他頁面中的常規頁面。我也檢查頁面的結束。

回答

1

它的發生,因爲一個細胞你觸發頁面分頁符。

要麼你在FPDF「自動分頁符」禁用或你要提前計算出細胞的高度一行。

正如你可以檢查出我FPDF表腳本替代: http://interpid.eu/fpdf-table

+0

非常感謝,現在是確定的。 – sinan 2012-04-20 11:22:58