• Generate Barcode using codeigniter with library zend barcode


    We can use ‘Zend Framework‘ library to generate barcode in our CodeIgniter project. To achieve this, we have to integrate relavent barcode library files from ZendFramework into our CodeIgniter (CI) project.
    Assuming you already have CodeIgniter installed. If not please refer to the user guide for installation.
    1. Download Zend Barcode from https://github.com/desta88/Codeigniter-Barcode-Generator-Zend-Library
    2. Copy the Zend.php & Zend folder (under Library) to your CodeIgniter installation’s application/libraries/. You can actually place the folder anywhere, but remember to alter the script accordingly (read the comments in the script!)
    3. Place the library script (provided at the end of the post) in application/libraries/
    4. Done! That’s all you need to do. Now, let us see an example of using the library.
    You can remove unnecessary files from Zend libraries. Just keep in mind that following folders and files are necessary under application\libraries\Zend folder for generating barcode –

    Folder – Barcode, Validate

    Files – Barcode.php, Exception.php, Loader.php, Validate.php
    Controller:
    //Barcode generation function, using Zend library
    function barcode()
    {
    $this->load->library('zend');
    $this->zend->load('Zend/Barcode');
    $id=$this->input->post('id');
            $barcodeOptions = array('text' => $id);
            $rendererOptions = array('imageType'          =>'png', 
                                     'horizontalPosition' => 'center', 
                                     'verticalPosition'   => 'middle');
    $imageResource=Zend_Barcode::factory('code128', 'image', $barcodeOptions, $rendererOptions)->render();
            return $imageResource;
     //End of Barcode generation function
    View
    <img src="<?php echo base_url(); ?>index.php/suggestion/barcode"  alt="not show" /></div>
    Display barcode as simple image
    $imageResource = Zend_Barcode::factory('code128', 'image', array('text'=>$barcode), array())->draw();
    imagepng($imageResource, 'public_html/img/barcode.png');
  • 0 comments:

    Post a Comment

    FAVOURITE LINE

    To steal ideas from one is plagiarism. To steal from many is Research.

    ADDRESS

    Mumbai , Maharashtra

    EMAIL

    shikha.pathak6@gmail.com
    shikha.the.swt.pari@gmail.com

    Skype

    shikha_pari