Documentation

Methods

API

Method Description Available from version
type(string $type)Allows indicating a desired type (standard) for barcode. List of possible values is available at Bitrix\UI\Util\Barcode\BarcodeDictionary.
Optional, set to QR by default.
format(string $format)Allows indicating a desired barcode format. List of possible values is available in Bitrix\UI\Util\Barcode\BarcodeDictionary.
Optional, set to png by default.
option(string $optionName, $value)Employed library supports large number of options, allowing to customize the result. This method can indicate value for a specific option. Full list of available options can be found at the library page https://github.com/kreativekorp/barcode.
options(array $options) Employed library supports large number of options, allowing to customize the result. This method can set values for all options at once. Full list of available options can be found at the library page https://github.com/kreativekorp/barcode.
render(string $message)Generates a barcode with specified message and returns a result.
print(string $message)Generates a barcode with specified message and prints the result in the output stream.

Example

use Bitrix\UI\Barcode\BarcodeDictionary;
use Bitrix\UI\Barcode\Barcode;

// generates barcode in .gif format and directly prints to output
$message = '1234567890';
(new Barcode())
    ->type(BarcodeDictionary::TYPE_UPC_A)
    ->format(BarcodeDictionary::FORMAT_GIF)
    ->print($message);
    
// creates QR code and further saving to file
// Uses QR type and .png format by default
$link = 'https://google.com';
$content = (new Barcode())->render($link);
$arFile = array(
    'name' => 'myCode.png',
    'content'  => $content,
    'module_id' => 'ui'
);
$fileId = \CFile::SaveFile($arFile, 'ui');

// generates with indicated linear dimensions
(new Barcode())
    ->type(BarcodeDictionary::TYPE_QR)
    ->format(BarcodeDictionary::FORMAT_JPEG)
    ->option('w', 150)
    ->option('h', 150)
    ->render($link);

© «Bitrix24», 2001-2024