Search by

object-oriented ZPL command builder

Package info

github.com/smart-dato/zpl

pkg:composer/smart-dato/zpl

Fund package maintenance!

SmartDato

Statistics

Installs: 4 869

Dependents: 0

Suggesters: 0

Stars: 0

0.0.3 2025-03-14 07:53 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

An object-oriented builder for Zebra Programming Language (ZPL) label code. Compose a label from text, Code 128 barcodes, boxes, lines and graphics, then render it to a ZPL string. Plain PHP, no framework required.

Requirements

  • PHP 8.2+

Installation

composer require smart-dato/zpl

Usage

use SmartDato\Zpl\Enums\InternationalEncoding;
use SmartDato\Zpl\Enums\OrientationType;
use SmartDato\Zpl\Label;

$label = new Label;
$label->setInternationalEncoding(InternationalEncoding::UTF8);
$label->setDefaultOrientation(OrientationType::ROTATED);

$label->addBox(710, 1120, 3)->at(50, 50);
$label->addLineOrthogonal(710, 3)->at(50, 800);

$label->addBarcode128('OLS202400001234X1')
    ->at(635, 90)
    ->withBarcodeDefaults(moduleWidth: 3, wideNarrowWidthRatio: 2.0, barcodeHeight: 80);

$label->setDefaultFont('D', 30);
$label->addText('Max Mustermann')->at(550, 90);
$label->addText('1140 Wien')->at(510, 90);

$zpl = $label->render();                     // one line
$zpl = $label->render(insertNewLines: true); // one command per line

render() wraps everything in ^XA^XZ. Elements are rendered in the order you add them, and setDefaultFont(), setDefaultOrientation() and setInternationalEncoding() apply to the elements added after them.

Elements

Method Returns
addText(string $text, bool $enableHexEncoding = false, ?string $hexIndicator = null) Text
addBarcode128(string $data, ?bool $ucc = null, ?string $mode = null) Barcode128
addBox(?int $width, ?int $height, ?int $borderThickness, ?LineColor $lineColor, ?int $cornerRounding) GraphicBox
addLineOrthogonal(?int $length, ?int $thickness, ?LineColor $lineColor, bool $rotated = false) GraphicBox
addGraphic(CompressionType $compression, int $binaryByteCount, int $graphicFieldCount, int $bytesPerRow, string $data) GraphicField

Every element is positioned with ->at($x, $y) (or ->origin(), ->x(), ->y()). Text and barcodes accept ->font(); barcodes also accept ->withBarcodeDefaults() and ->interpretationText().

Invalid command arguments throw InvalidCommandArgumentsException.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.