00001 <?php
00002 require('../fpdf.php');
00003
00004 class PDF extends FPDF
00005 {
00006
00007 function LoadData($file)
00008 {
00009
00010 $lines=file($file);
00011 $data=array();
00012 foreach($lines as $line)
00013 $data[]=explode(';',chop($line));
00014 return $data;
00015 }
00016
00017
00018 function BasicTable($header,$data)
00019 {
00020
00021 foreach($header as $col)
00022 $this->Cell(40,7,$col,1);
00023 $this->Ln();
00024
00025 foreach($data as $row)
00026 {
00027 foreach($row as $col)
00028 $this->Cell(40,6,$col,1);
00029 $this->Ln();
00030 }
00031 }
00032
00033
00034 function ImprovedTable($header,$data)
00035 {
00036
00037 $w=array(40,35,40,45);
00038
00039 for($i=0;$i<count($header);$i++)
00040 $this->Cell($w[$i],7,$header[$i],1,0,'C');
00041 $this->Ln();
00042
00043 foreach($data as $row)
00044 {
00045 $this->Cell($w[0],6,$row[0],'LR');
00046 $this->Cell($w[1],6,$row[1],'LR');
00047 $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R');
00048 $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R');
00049 $this->Ln();
00050 }
00051
00052 $this->Cell(array_sum($w),0,'','T');
00053 }
00054
00055
00056 function FancyTable($header,$data)
00057 {
00058
00059 $this->SetFillColor(255,0,0);
00060 $this->SetTextColor(255);
00061 $this->SetDrawColor(128,0,0);
00062 $this->SetLineWidth(.3);
00063 $this->SetFont('','B');
00064
00065 $w=array(40,35,40,45);
00066 for($i=0;$i<count($header);$i++)
00067 $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
00068 $this->Ln();
00069
00070 $this->SetFillColor(224,235,255);
00071 $this->SetTextColor(0);
00072 $this->SetFont('');
00073
00074 $fill=false;
00075 foreach($data as $row)
00076 {
00077 $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
00078 $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
00079 $this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
00080 $this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
00081 $this->Ln();
00082 $fill=!$fill;
00083 }
00084 $this->Cell(array_sum($w),0,'','T');
00085 }
00086 }
00087
00088 $pdf=new PDF();
00089
00090 $header=array('Country','Capital','Area (sq km)','Pop. (thousands)');
00091
00092 $data=$pdf->LoadData('countries.txt');
00093 $pdf->SetFont('Arial','',14);
00094 $pdf->AddPage();
00095 $pdf->BasicTable($header,$data);
00096 $pdf->AddPage();
00097 $pdf->ImprovedTable($header,$data);
00098 $pdf->AddPage();
00099 $pdf->FancyTable($header,$data);
00100 $pdf->Output();
00101 ?>