2017-09-30 3 views
0

Je rencontre des problèmes pour afficher l'image en utilisant la bibliothèque fpdf. J'utilise fpdf Table avec des scripts MultiCells [http://www.fpdf.org/?go=script&id=3].fpdf Afficher l'image dans la rangée du tableau en utilisant la table avec multilcell

Je peux afficher les données en appelant cette fonction

$data = [ 
    ['A','B','C','image_path'], 
    ['A','B','C','image_path'], 
    ['A','B','C','image_path'], 
]; 
$pdf->Row($header); 
foreach($data as $v) $pdf->Row($v); 

Il produira des données bien. Je veux remplacer image_path par une image. Comment puis-je afficher une image en utilisant ce script?

Mon pdf ressemblera à ceci. enter image description here

Répondre

1

Modifier la classe PDF_MC_Table Les fonctions Row() utilisent Inhertence.

Class Pdf extends PDF_MC_Table{ 
    protected $imageKey = ''; 

    public function setImageKey($key){ 
    $this->imageKey = $key; 
    } 

    public function Row($data){ 
    $nb=0; 
    for($i=0;$i<count($data);$i++) 
     $nb=max($nb,$this->NbLines($this->widths[$i],$data[$i])); 
     $h=5*$nb; 
     $this->CheckPageBreak($h); 
     for($i=0;$i<count($data);$i++){ 
     $w=$this->widths[$i]; 
     $a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L'; 
     $x=$this->GetX(); 
     $y=$this->GetY(); 
     $this->Rect($x,$y,$w,$h); 

     //modify functions for image 
     if(!empty($this->imageKey) && in_array($i,$this->imageKey)){ 
      $ih = $h - 0.5; 
      $iw = $w - 0.5; 
      $ix = $x + 0.25; 
      $iy = $y + 0.25; 
      $this->MultiCell($w,5,$this->Image ($data[$i],$ix,$iy,$iw,$ih),0,$a); 
     } 
     else 
      $this->MultiCell($w,5,$data[$i],0,$a); 
     $this->SetXY($x+$w,$y); 
     } 
     $this->Ln($h); 
    } 
    } 

} 

appeler maintenant cette fonction comme celui-ci

$data = [ 
    ['A','B','C','image_path'], 
    ['A','B','C','image_path'], 
    ['A','B','C','image_path'], 
]; 

$pdf = new Pdf(); 
$pdf->AddPage(); 
$pdf->setImageKey = [4]; 
$pdf->Row($data);