PHP code example of beziworld / laravel-label-printing
1. Go to this page and download the library: Download beziworld/laravel-label-printing 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/ */
beziworld / laravel-label-printing example snippets
// config/label-printing.php
'printers' => [
'warehouse' => ['driver' => 'network', 'language' => 'zpl', 'host' => env('LABEL_PRINTER_HOST'), 'port' => 9100,
'timeout' => 5, 'dpi' => 203, 'label_width' => 812, 'label_length' => 1218],
'receipt' => ['driver' => 'network', 'language' => 'escpos', 'host' => env('RECEIPT_PRINTER_HOST'),
'profile' => 'default', 'code_page' => 'cp852', 'code_page_table' => null, 'columns' => 48],
'office' => ['driver' => 'cups', 'language' => 'zpl', 'destination' => 'Zebra_ZD421', 'host' => null, 'options' => []],
'desk' => ['driver' => 'windows', 'language' => 'zpl', 'share' => '\\\\SHOP-PC\\Zebra',
'username' => null, 'password' => null, 'workgroup' => null, 'method' => 'auto'],
'capture' => ['driver' => 'file', 'language' => 'raw', 'path' => storage_path('app/label-printing/capture.prn'), 'append' => true],
'null' => ['driver' => 'null', 'language' => 'raw'],
],
'queue' => ['connection' => null, 'queue' => 'printing', 'tries' => 5, 'backoff' => [5, 15, 60, 180]],
use Beziworld\LabelPrinting\Facades\LabelPrinter;
// Raw ZPL bytes, for example from laravel-inpost or laravel-gls
LabelPrinter::printer('warehouse')->zpl($zplFromCourier);
// Base64 ZPL from a JSON API (for example DPD or DHL), two copies, with a reference for events and logs
LabelPrinter::printer('warehouse')->zplBase64($label->content, copies: 2, reference: $shipment->number);
// EPL2 labels
LabelPrinter::printer('warehouse')->epl($eplFromCourier);
// Anything else, unvalidated
LabelPrinter::printer('capture')->raw($bytes);
use Beziworld\LabelPrinting\Enums\QrErrorCorrection;
$printer = LabelPrinter::printer('warehouse');
$label = $printer->label() // ^PW / ^LL from label_width, label_length and dpi
->text(40, 40, 'Zamówienie #1024', height: 50)
->textBlock(40, 110, 730, "ul. Długa 5/3\n30-001 Kraków", height: 32, maxLines: 3)
->code128(40, 230, 'ORD-1024', height: 120)
->ean13(40, 420, '590123412345')
->qr(560, 420, 'https://example.com/o/1024', magnification: 5, errorCorrection: QrErrorCorrection::Quartile)
->box(20, 20, 772, 600, thickness: 3)
->image(560, 40, file_get_contents(resource_path('logo.png')))
->copies(2);
$printer->zpl($label);
$label->toZpl(); // the exact ZPL string
$label->mm(25); // 200 dots at 203 dpi
$receipt = LabelPrinter::receipt()
->center()->bold()->doubleSize()->line('SKLEP ŻÓŁTY')->normal()
->center()->line('ul. Prosta 1, 00-001 Warszawa')
->left()->divider()
->columns('Kawa ziarnista 1 kg', '89,00 zł')
->columns('Herbata', '12,50 zł')
->divider('=')
->bold()->columns('RAZEM', '101,50 zł')->bold(false)
->feed()
->center()->barcode('ORD-1024') // Code 128; also Barcode::Ean13, Ean8, Code39
->qr('https://example.com/r/1024', size: 6)
->line('To nie jest paragon fiskalny')
->feed(3)
->cut()
->openCashDrawer();
LabelPrinter::printer('receipt')->escpos($receipt);
LabelPrinter::printer('warehouse')->queue()->zpl($zpl, reference: $shipment->number);
LabelPrinter::printer('receipt')->queue('redis', 'pos')->escpos($receipt);
$printer = LabelPrinter::using(['driver' => 'network', 'host' => $station->ip, 'language' => 'zpl'], 'station-'.$station->id);
$printer->zpl($zpl);
use Beziworld\LabelPrinting\Facades\LabelPrinter;
$fake = LabelPrinter::fake();
// ... code that prints
$fake->assertPrinted('warehouse');
$fake->assertPrinted('warehouse', "^XA\n...^XZ\n");
$fake->assertPrinted('receipt', fn (string $bytes) => str_contains($bytes, "\x1DVA"));
$fake->assertPrintedCount(2);
$fake->failNext(); // simulate an unreachable printer
$fake->printed('warehouse'); // list of captured byte strings