PHP code example of tomasvotruba / barcode-bundle

1. Go to this page and download the library: Download tomasvotruba/barcode-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomasvotruba / barcode-bundle example snippets


      // app/AppKernel.php
      public function registerBundles()
      {
          return [
              // ...
              new \TomasVotruba\BarcodeBundle\BarcodeBundle(),
          ];
      }

use TomasVotruba\BarcodeBundle\Base1DBarcode;

$myBarcode = new Base1DBarcode();
$myBarcode->savePath = '/my/temp/media/path';

$bcPathAbs = $myBarcode->getBarcodePNGPath('501234567890', 'EAN13', 1.75, 45);
$bcHTMLRaw = $myBarcode->getBarcodeHTML('501234567890', 'EAN13', 1.75, 45);

 /**
  * 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';
 }

 $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 }}
 // ...