1

目前我正在开发opencart。我必须以 pdf 格式显示数据,因为我使用 FPDF。

我的功能看起来像

public function exportPDF(){
require_once(DIR_SYSTEM . 'lib/fpdf.php');
$pdf = new fpdf();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);

$category_id = $this->request->get['id'];

$this->load->model('catalog/product');
$this->load->model('tool/image');

$temp_data = $this->model_catalog_product->getProductscsv($category_id); 

foreach($temp_data as $data)
{
    if ($data['image']) {
        $image = $this->model_tool_image->resize($data['image'], 178, 276);
    } else {
        $image = $this->model_tool_image->resize('placeholder.png', 178, 276);
    }
    $data2[] = array(
    'product_id' =>$data['product_id'],
    'model' =>$data['model'],
    'name' =>$data['name'],
    'price' =>$data['price'],
    'image' =>$image,          
    );     
}    
$row = array();
$pdf->SetFont('Arial','',12);   
$pdf->Ln();
$pdf->Cell(35,10,'id',1);
$pdf->Cell(35,10,'model',1);
$pdf->Cell(35,10,'name',1);
$pdf->Cell(35,10,'price',1);
$pdf->Cell(35,10,'image',1);

foreach($data2 as $row)
{  
   $pdf->SetFont('Arial','',10);    
   $pdf->Ln();    
   foreach($row as $column)
    $pdf->Cell(35,50,$column,1);
}
$pdf->Output();   
}

当前输出的pdf看起来像: 在此处输入图像描述

我的需要是我需要在图像列而不是链接中显示图像。怎么可能。我对此很陌生,并且尝试了很长时间。如何使用$pdf->Image(); $data2 数组中。如何在pdf中的图像列中显示图像。

4

2 回答 2

1

尝试这个,

foreach($data2 as $row)
{  
    $pdf->SetFont('Arial','',10);    
    $pdf->Ln();    
    foreach($row as $key=>$column)
    {  
       if($key == "image"){
             $pdf->Cell(35,50,$this->Image($column,$this->GetX(),$this->GetY()),1);
       }else{           
            $pdf->Cell(35,50,$column,1);         
       } 
    } 
}

并阅读:参考

于 2016-10-18T10:31:39.957 回答
0

试试这个代码

$this->Cell( 35,10, $pdf->Image($image, $pdf->GetX(), $pdf->GetY()), 0, 0, 'L', false );
于 2016-10-18T10:33:14.040 回答