【问题标题】:How to generate barcode in PDF using zend library in codeigniter 3.x如何使用codeigniter 3.x中的zend库在PDF中生成条形码
【发布时间】:2017-06-06 09:23:24
【问题描述】:

我正在使用 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());
    }

【问题讨论】:

  • 嗯...有什么问题?
  • 我想把这个改成pdf怎么做
  • $pdf = new Zend_Barcode_Renderer_Pdf(); $barcodeOptions = array('text' => '11111', ); $rendererOptions = array('topOffset' => 50, 'leftOffset' => 50, ); Zend_Barcode::factory('code39', 'pdf', $barcodeOptions, $rendererOptions)->setResource($pdf)->draw();
  • 在上面尝试过,但不起作用
  • 收到此错误遇到未捕获的异常类型:错误消息:找不到类“Zend_Pdf”文件名:/var/www/html/poswift-reynolds-ui/application/controllers/Item.php行号:408 回溯:文件:/var/www/html/poswift-reynolds-ui/index.php 行:315 功能:require_once

标签: php codeigniter zend-framework


【解决方案1】:

首先使用mpdf创建一个pdf文件如viewpdf.php,并调用tag中的barcode函数。

在视图文件夹中创建 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();

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 2013-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-27
    相关资源
    最近更新 更多