Home

Awesome

Introduction

This Bundle provide barcode rendering using our barcode generator base library https://github.com/paterik/BGBarcodeGenerator supports ImageMagick/GDLib based image rendering, svg and html table drawn output of the following 1D/2D bar codes:

1d barcodes

2d barcodes

Prerequisites

This version requires Symfony 2.1

Installation

1 - Add the following lines in your composer.json:

for latest symfony 3.n kernel / framework environment:

    "require": {
        "bitgrave/barcode-bundle": "^1.0"
    }

_legacy symfony 2.1.n kernel? user version prior 1.0.0:

    "require": {
        "bitgrave/barcode-bundle": "0.0.9"
    }

2 - Run the composer to download the bundle

    $ php composer.phar update bitgrave/barcode-bundle

3 - Add this bundle to your application's kernel:

      // app/AppKernel.php
      public function registerBundles()
      {
          return array(
              // ...
              new BG\BarcodeBundle\BarcodeBundle(),
              // ...
          );
      }

Usage

1 - Add the following lines in your controller if you want to use both code types (1d/2d) :

use BG\BarcodeBundle\Util\Base1DBarcode as barCode;
use BG\BarcodeBundle\Util\Base2DBarcode as matrixCode;

2 - set the cache path (for image based barcode rendering) call the image- or html renderer including your code and barcode type :

 $myBarcode = new barCode();
 $myBarcode->savePath = '/my/temp/media/path';
 $bcPathAbs = $myBarcode->getBarcodePNGPath('501234567890', 'EAN13', 1.75, 45);
 $bcHTMLRaw = $myBarcode->getBarcodeHTML('501234567890', 'EAN13', 1.75, 45);

3 - fetch image by parse $bcPathAbs (absolute path to rendered barcode image) or using this a simple helper method

 /**
  * simple cache path returning method (sample cache path: "upload/barcode/cache" )
  *
  * @param bool $public
  *
  * @return string
  *
  */
 protected function getBarcodeCachePath($public = false)
 {

     return (!$public) ? $this->get('kernel')->getRootDir(). '/../web/upload/barcode/cache' : '/upload/barcode/cache';
 }

4 - send public path to your symfony view and put result into your image src path or just render out the alternative table based barcode html structure

 $this->render('AcmeDemoBundle:Demo:barcode.html.twig', array(
     'barcodePathAndFile' => $this->getBarcodeCachePath($bcPathAbs),
     'barcodeHTML' => $bcHTMLRaw,
 ));

 // AcmeDemoBundle:Demo:barcode.html.twig
 // ...
 <!-- barcode as image -->
 <img src="{{ barcodePathAndFile }}" alt="barcode" title="my barcode image">
 // ...
 <!-- barcode as table -->
 {{ barcodeHTML|raw }}
 // ...

How To Contribute

To contribute changes, fixes, additions/features please open a pull request with your new code. please take not, that if you add new features or modify existing ones you have to doc this in projects README file (also update projects CHANGELOG file!)

License

See: resources/meta/LICENSE