Codice PHP:
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Path file da stampare
$dir = 'class/fpdf/filetoprint/';
$file= $dir. $file;
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Better table
function ImprovedTable($header,$data)
{
//Column widths
$w=array(10,11,40,55,30,7,8,7,10,10);
//Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'L');
$this->Ln();
//Data
foreach($data as $row)
{
$this->Cell($w[0],4,$row[0],'1',0,'L',$fill);
$this->Cell($w[1],4,$row[1],'1',0,'L',$fill);
$this->Cell($w[2],4,$row[2],'1',0,'L',$fill);
$this->Cell($w[3],4,$row[3],'1',0,'L',$fill);
$this->Cell($w[4],4,$row[4],'1',0,'L',$fill);
$this->Cell($w[5],4,$row[5],'1',0,'C',$fill);
$this->Cell($w[6],4,$row[6],'1',0,'C',$fill);
$this->Cell($w[7],4,$row[7],'1',0,'C',$fill);
$this->Cell($w[8],4,$row[8],'1',0,'C',$fill);
$this->Cell($w[9],4,$row[9],'1',0,'C',$fill);
$this->Ln();
}
//Closure line
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('NUM','COD','MARCA','CATEGORIA','COLORE','STG','TIPO','SE','TG','QTA');
//Data loading
$data=$pdf->LoadData('articoli.txt');
$pdf->SetFont('Arial','',6);
$pdf->AddPage();
$pdf->ImprovedTable($header,$data);
$pdf->Output();
?>