2011-06-06 24 views
1

我正在使用FPDF(從PHP生成PDF)。我想在表格標題中顯示數組中的所有項目,但僅顯示一些項目,例如列表太大而不適合,但格式不正確。我還不明白如何移動我的表格標題的尺寸。爲什麼我的表格不適合PDF輸出?

header for table

這是我的代碼:

<?php 
require('fpdf.php'); 

class PDF extends FPDF 
{ 
//Load data 
function LoadData($file) 
{ 
//Read file lines 
$lines=file($file); 
$data=array(); 
foreach($lines as $line) 
    $data[]=explode(';',chop($line)); 
return $data; 
    } 

    //Colored table 
    function FancyTable($header,$data) 
    { 
//Colors, line width and bold font 
$this->SetFillColor(255,0,0); 
$this->SetTextColor(255); 
$this->SetDrawColor(128,0,0); 
$this->SetLineWidth(.3); 
$this->SetFont('','B'); 
//Header 
$w=array(40,35,40,45); 
for($i=0;$i<count($header);$i++) 
    $this->Cell($w[$i],7,$header[$i],1,0,'C',true); 
$this->Ln(); 


$this->Cell(array_sum($w),0,'','T'); 
    } 
    } 

    $pdf = new PDF('L', 'mm', 'A4'); 
    //Column titles 
    $header=array('Name','Surname','Date','Start','Br Start','Br End','Start','End','Centre'); 
    //Data loading 
    $data=$pdf->LoadData('countries.txt'); 
    $pdf->SetFont('Arial','',12); 
    $pdf->AddPage(); 
    $pdf->FancyTable($header,$data); 
    $pdf->Output(); 
     ?> 

回答

1

在您的代碼:

$w=array(40,35,40,45); 
for($i=0;$i<count($header);$i++) 

如果count($頭)> 4,那麼你就麻煩了......這就像我在屏幕截圖中看到的那樣。 對於未定義的值,您將有0作爲第一個參數...這意味着全寬。

PS:打開錯誤報告來查看你的錯誤,當然PHP會拋出它們。