du1462 2017-09-30 07:01
浏览 63
已采纳

fpdf使用带有multilcell的表在表行中显示图像

I am having trouble displaying image using fpdf library. I use fpdf Table with MultiCells scripts [http://www.fpdf.org/?go=script&id=3 ].

I can display data by calling this function

$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);

It will generate data nicely. I want to replace image_path with image . How can I display image using this script?

My pdf will be look like this. enter image description here

  • 写回答

1条回答 默认 最新

  • dqrqp8492 2017-09-30 13:57
    关注

    Modify PDF_MC_Table class Row() functions by using 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);
        }
      }
    
    }
    

    Now call this function like this

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本