Advertisement
Guest User

FPDF extension

a guest
Jul 30th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. # using last version of FPDF 1.7: http://www.fpdf.org/
  4. require_once './fpdf17/fpdf.php';
  5.  
  6. class PDF extends FPDF
  7. {
  8.     public function BuildTable2($header2,$data2)
  9.     {
  10.         $this->SetFillColor(255,255,255);
  11.         $this->SetTextColor(0);
  12.         $this->SetDrawColor(0);
  13.         $this->SetLineWidth(.3);
  14.         $this->SetFont('','B');
  15.  
  16.         //Header
  17.         $w = array(20,20,40,18,50,12);
  18.         $this->SetFont('Arial','B',7);
  19.  
  20.         for($i=0;$i<count($header2);$i++) $this->Cell($w[$i],7,$header2[$i],1,0,'C',true);
  21.         $this->Ln();
  22.  
  23.         //Color and font restoration
  24.         $this->SetFillColor(224,235,255);
  25.         $this->SetTextColor(0);
  26.         $this->SetFont('');
  27.  
  28.         //Data
  29.         $fill=false;
  30.         $i = 0;
  31.         $x0=$x = $this->GetX();
  32.         $y = $this->GetY();
  33.  
  34.         foreach($data2 as $row)
  35.         {
  36.             for ($i=0; $i<6; $i++) //Avoid very lengthy texts
  37.             {
  38.                 $row[$i]=substr($row[$i],0,160);
  39.             }
  40.  
  41.             $yH=9; //height of the row
  42.  
  43.             //Issue a page break first if needed
  44.             $this->SetXY($x, $y);
  45.             $this->Cell($w[0], $yH, "", 'LRB',0,'',$fill);
  46.             $this->SetXY($x, $y);
  47.             $this->MultiCell($w[0],6,$row[0],0,'L');
  48.  
  49.             $this->SetXY($x + $w[0], $y);
  50.             $this->Cell($w[1], $yH, "", 'LRB',0,'',$fill);
  51.             $this->SetXY($x + $w[0], $y);
  52.             $this->MultiCell($w[1],4,$row[1],0,'L');
  53.  
  54.             $x =$x+$w[0];
  55.             $this->SetXY($x + $w[1], $y);
  56.             $this->Cell($w[2], $yH, "", 'LRB',0,'',$fill);
  57.             $this->SetXY($x + $w[1], $y);
  58.             $this->MultiCell($w[2],5,$row[2],0,'L');
  59.  
  60.             $x =$x+$w[1];
  61.             $this->SetXY($x + $w[2], $y);
  62.             $this->Cell($w[3], $yH, "", 'LRB',0,'',$fill);
  63.             $this->SetXY($x + $w[2], $y);
  64.             $this->MultiCell($w[3],6,$row[3],0,'L');
  65.  
  66.             $x =$x+$w[2];
  67.             $this->SetXY($x + $w[3], $y);
  68.             $this->Cell($w[4], $yH, "", 'LRB',0,'',$fill);
  69.             $this->SetXY($x + $w[3], $y);
  70.             $this->MultiCell($w[4],6,$row[4],0,'L');
  71.  
  72.             $x =$x+$w[3];
  73.             $this->SetXY($x + $w[4], $y);
  74.             $this->Cell($w[5], $yH, "", 'LRB',0,'',$fill);
  75.             $this->SetXY($x + $w[4], $y);
  76.             $this->MultiCell($w[5],6,$row[5],0,'L');
  77.  
  78.             $y=$y+$yH; //move to next row
  79.             $x=$x0; //start from firt column
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement