【发布时间】:2011-06-06 02:32:48
【问题描述】:
我正在使用FPDF(从 PHP 生成 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();
?>
【问题讨论】:
标签: php pdf-generation fpdf