1
我正在使用FPDF(從PHP生成PDF)。我想在表格標題中顯示數組中的所有項目,但僅顯示一些項目,例如列表太大而不適合,但格式不正確。我還不明白如何移動我的表格標題的尺寸。爲什麼我的表格不適合PDF輸出?
這是我的代碼:
<?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();
?>