Setting Up Label and Barcode Printing in 1C-Bitrix
Warehouse receives a new batch, each product must be labeled. Employee opens the product card in Bitrix, copies the name, SKU, pastes into Word, prints. Multiply that by 200 positions. This either ends in labeling errors or reprinting half the batch.
Barcodes in Catalog
Barcodes are stored in table b_catalog_product_barcode: PRODUCT_ID, BARCODE, TYPE (code type: EAN13, Code128, QR, etc.). One product can have multiple barcodes of different types.
Getting product barcodes:
$barcodes = \Bitrix\Catalog\ProductBarcodeTable::getList([
'filter' => ['PRODUCT_ID' => $productId],
'select' => ['BARCODE', 'TYPE'],
])->fetchAll();
If a product has no barcode, it's generated. EAN-13 auto-generation from product ID:
function generateEan13FromId(int $productId): string {
$code = str_pad($productId, 12, '0', STR_PAD_LEFT);
// Calculate EAN-13 check digit
$sum = 0;
for ($i = 0; $i < 12; $i++) {
$sum += (int)$code[$i] * ($i % 2 === 0 ? 1 : 3);
}
$checkDigit = (10 - ($sum % 10)) % 10;
return $code . $checkDigit;
}
After generation, the barcode is saved in b_catalog_product_barcode.
Barcode Image Generation
For generating barcode images, PHP libraries are used. In the Bitrix ecosystem, picqer/php-barcode-generator or a custom GD-based class are most common. Installation via Composer:
composer require picqer/php-barcode-generator
Generating EAN-13 in SVG for printing:
$generator = new \Picqer\Barcode\BarcodeGeneratorSVG();
$svg = $generator->getBarcode('4607134392015', $generator::TYPE_EAN_13, 3, 60);
SVG is preferable to PNG for printing — scales without quality loss at any DPI.
Label Template
A label is assembled as an HTML page and sent to print via browser or converted to PDF. Minimal template for printing via @media print:
<!DOCTYPE html>
<html>
<head>
<style>
@page { size: 58mm 40mm; margin: 2mm; }
body { font-family: Arial; font-size: 8pt; }
.label { width: 54mm; height: 36mm; display: flex; flex-direction: column; }
.barcode { text-align: center; }
.name { font-size: 7pt; overflow: hidden; max-height: 12mm; }
.price { font-size: 14pt; font-weight: bold; text-align: right; }
</style>
</head>
<body>
<div class="label">
<div class="name"><?= htmlspecialchars($product['NAME']) ?></div>
<div class="price"><?= $price ?> rubles</div>
<div class="barcode"><?= $svg ?></div>
<div style="text-align:center; font-size:7pt"><?= $barcode ?></div>
</div>
</body>
</html>
Page size 58mm 40mm is the standard for Zebra/Godex label printer with 58mm width.
Admin Interface for Printing
The label selection and printing interface is embedded in the Bitrix admin via a custom page in /bitrix/admin/. The page accepts a list of PRODUCT_ID[] via GET parameters (passed from product list via "Actions on selected"), renders labels, calls window.print().
For batch printing — multiple labels on one A4 sheet — use grid layout with fixed cell sizes for label format. When printing, CSS break-inside: avoid prevents label breaks between pages.
Integrating with Label Printer
Zebra and similar printers accept ZPL (Zebra Programming Language) or EPL commands. For direct sending to a network printer from PHP:
$socket = fsockopen('192.168.1.100', 9100, $errno, $errstr, 5);
if ($socket) {
$zpl = buildZplLabel($product, $barcode);
fwrite($socket, $zpl);
fclose($socket);
}
This works for batch printing without opening a browser window and is faster for large volumes. Printing via browser requires confirmation for each sheet — for 200 labels, this is unacceptable.







