如何在 codeigniter 中使用 zend 库在 PDF 中生成条形码 3.x
How to generate barcode in PDF using zend library in codeigniter 3.x
我正在使用 zend 库 生成 barcode
如何生成带标题的条形码。下面是我的代码
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());
}
先用mpdf创建一个pdf文件如viewpdf.php,在tag中调用条码函数
在视图文件夹中创建 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文件夹下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();
}
我正在使用 zend 库 生成 barcode
如何生成带标题的条形码。下面是我的代码
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());
}
先用mpdf创建一个pdf文件如viewpdf.php,在tag中调用条码函数
在视图文件夹中创建 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文件夹下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();
}