2017-06-06 24 views
1

我正在使用zend库生成barcode如何使用标题生成条形码。以下是我的代码如何在codeigniter 3.x中使用zend库生成PDF条形码

public function barcode($visitor_id) { 
     $this->load->library('zend'); 
     $this->zend->load('Zend/Barcode'); 
     Zend_Barcode::render('code39', 'image', array('text' => $visitor_id, 'drawText' => TRUE), array()); 
    } 
+0

嗯...什么是问题? – VirCom

+0

我想将其更改为pdf如何做到这一点 –

+0

$ pdf = new Zend_Barcode_Renderer_Pdf(); \t \t $ barcodeOptions =阵列( \t \t \t '文本'=> '11111', \t \t); \t \t $ rendererOptions =阵列( \t \t \t 'topOffset'=> 50, \t \t \t '左偏移'=> 50, \t \t); \t \t Zend_Barcode ::工厂( 'CODE39', 'PDF', \t \t \t $ barcodeOptions,$ rendererOptions) - > setResource($ PDF) - >平局(); –

回答

1

首先使用mpdf创建一个pdf文件,例如viewpdf.php,并在标签中调用条形码功能。

鉴于文件夹中创建viewpdf.php

<?php 
$code= KD12345; 

include("mpdf/mpdf.php"); 
$html='<html> 
<head> 
    <style> 
    .container{width: 1450px; padding-bottom:2px;} 
    body, table { 
     /* to centre page on screen*/ 
     margin:0 auto; 
     font-size: 12px; 
     border-collapse: collapse; 
    } 
</style> 
</head> 
<body> 
<div class="container" style="padding-top:2%;"> 
      <img class="img-responsive" style="text-align:center;" src="'. base_url().'index.php/Controller/barcode?bcd='.$code.'" alt=""> 
     </div> 
</body> 
</html>'; 

$mpdf=new mPDF('', 'A4', 0, '', 2, 2,5, 0, 0, 0); 
header("Content-type:application/pdf"); 
$mpdf->SetDisplayMode('fullpage'); 
$mpdf->WriteHTML($html); 
$mpdf->Output($code.'.PDF','I'); 
exit; 
?> 

在控制器夹Controller.php这样写一个下面的函数来显示viewpdf.php

public function ViewPdf() 
    { 
     $this->load->view("viewpdf.php"); 
    } 

和用于生成另一功能条形码

public function barcode() 
    { 
     $code=$_GET['bcd']; 
     $this->load->library('zend'); 
     $this->zend->load('Zend/Barcode'); 

     $barcodeOptions = array('text' => $code); 
     $rendererOptions = array('imageType'=>'png'); 
     Zend_Barcode::factory('code128', 'image', $barcodeOptions, $rendererOptions)->render(); 

    }