PHP code example of diecoding / yii2-barcode-generator

1. Go to this page and download the library: Download diecoding/yii2-barcode-generator 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/ */

    

diecoding / yii2-barcode-generator example snippets


use diecoding\barcode\generator\Barcode;

// CODE128 (auto) is the default mode
Barcode::widget([
  'value' => 'Hi world!',
]);

// CODE128
Barcode::widget([
  'value'  => 'Example1234',
  'format' => Barcode::CODE128
]);

// CODE128A
Barcode::widget([
  'value'  => 'EXAMPLE\n1234',
  'format' => Barcode::CODE128A
]);

// ...


use diecoding\barcode\generator\Barcode;

Barcode::widget([
  'value'         => '1234',
  'format'        => Barcode::PHARMACODE,
  'pluginOptions' => [
    'lineColor'    => '#0aa',
    'width'        => 4,
    'height'       => 40,
    'displayValue' => false
  ]
]);

// Enable encoding CODE128 as GS1-128/EAN-128.
Barcode::widget([
  'value'         => '12345678',
  'format'        => Barcode::CODE128C,
  'pluginOptions' => [
    'ean128' => true,
  ]
]);

// Change Element Tag, default svg, available svg, img, canvas
Barcode::widget([
  'tag'           => 'img',
  'value'         => '12345678',
  'format'        => Barcode::CODE128C,
  'pluginOptions' => [
    'ean128' => true,
  ]
]);

// Change Element Tag, add custom style element tag, hide value text
Barcode::widget([
  'tag'     => 'img',
  'value'   => '12345678',
  'options' => [
      'style' => "width: 4cm; height: 1cm;",
  ],
  'pluginOptions' => [
      'displayValue' => false,
  ],
]);

// ...