andersonls/zpl
Composer 安装命令:
composer require andersonls/zpl
包简介
This library is a php wrapper for the ZPL Programming Language.
关键字:
README 文档
README
Installation:
composer require andersonls/zpl
How to use
Below are concise examples showing common (simple) and more advanced usages of the library.
Simple usage (create a label with one cell and print it):
<?php require __DIR__ . '/vendor/autoload.php'; // Use millimeters for coordinates and dimensions use Zpl\Enums\Unit; use Zpl\Enums\Align; $driver = new \Zpl\ZplBuilder(Unit::MM); // Set encoding (optional) $driver->setEncoding(28); $driver->setFont('0', 16); $driver->setXY(0, 0); $driver->drawCell(100, 10, 'Hello World', true, true, Align::CENTER); $zpl = $driver->toZpl(); \Zpl\Printer::printer('192.168.1.1')->send($zpl);
Advanced usage (multiple elements, barcodes, QR codes, graphics, pages and raw commands):
<?php require __DIR__ . '/vendor/autoload.php'; use Zpl\Enums\Unit; $driver = new \Zpl\ZplBuilder(Unit::MM); $driver->setFontMapper(new \Zpl\Fonts\Generic()); $driver->setDpi(300); // change printer DPI when needed // Draw shapes $driver->drawRect(5, 5, 50, 30); $driver->drawCircle(60, 5, 25); // Text with explicit coordinates use Zpl\Enums\Orientation; $driver->drawText(5, 40, 'Product: ABC-123', Orientation::NORMAL); // Code 128 barcode (x, y, height, data, print human-readable?) $driver->drawCode128(5, 50, 20, 'ABC123456789', true); // QR Code (x, y, data, module size) $driver->drawQrCode(50, 50, 'https://example.com/product/ABC-123', 6); // Add an image/graphic. width is optional and will scale the graphic field in dots $driver->drawGraphic(120, 10, __DIR__ . '/logo.png', 200); // Add custom/pre/post raw commands (you can use ^XA, ^XZ and any other ZPL commands) $driver->addPreCommand('^LH0,0'); // set label home $driver->addPostCommand('^PQ1'); // print quantity 1 // New page (adds a new label) - useful if you want to print multiple labels in one ZPL payload $driver->newPage(); $driver->drawText(5, 5, 'Second label'); // You can call arbitrary ZPL commands using method-like calls (dynamic): CF is same as ^CF $driver->CF('A', 30); // ^CFA,30 (be careful with arguments and expected format) \Zpl\Printer::printer('192.168.1.100')->send($driver->toZpl());
Macros
You can extend the ZplBuilder with custom macros to add reusable commands or behaviors. Macros are registered using the macro() method and can be called as if they were native methods.
Registering a Macro
$builder = new \Zpl\ZplBuilder('mm'); \Zpl\ZplBuilder::macro('drawCustomBox', function($x, $y, $w, $h) { $this->drawRect($x, $y, $w, $h); $this->drawText($x + 2, $y + 2, 'Custom'); });
Using a Macro
$builder->drawCustomBox(10, 10, 50, 20);
Notes
- Macros have access to the builder instance via
$this. - You can override existing methods, but use caution to avoid breaking core functionality.
- Macros are useful for encapsulating label patterns, custom shapes, or repetitive tasks.
Notes and tips
- Units: the constructor accepts a Unit enum (for example:
Unit::MMorUnit::DOTS). When usingUnit::MM, coordinates are converted to printer dots using the configured DPI (default 203). - DPI: default resolution is 203 DPI. Use
setDpi()to change it orgetDpi()to read it. - Font mapping: use
setFontMapper()to provide a mapper implementing\Zpl\Fonts\AbstractMapper(the included\Zpl\Fonts\Genericmaps logical font ids to ZPL fonts). - Special characters: common control characters are converted to their ZPL-safe hex sequences automatically (see library mappings for details).
- Debugging: write the ZPL to a file and inspect it or send it to a printer emulator before printing on physical media.
Donations
If this project helps you somehow, you can give me a cup of coffee :)
andersonls/zpl 适用场景与选型建议
andersonls/zpl 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 139.17k 次下载、GitHub Stars 达 35, 最近一次更新时间为 2018 年 08 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「zpl」 「php-wrapper」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 andersonls/zpl 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 andersonls/zpl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 andersonls/zpl 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP ZPL builder, image conversion and a basic client for network-connected Zebra label printers.
Convert a PDF file to a ZPL file
An unofficial PHP wrapper for the official Claim.MD API.
A simple PHP library for building ZPL (Zebra Programming Language) label payloads.
The most comprehensive PHP SDK for Canvas LMS API. Production-ready with 45 APIs implemented, rate limiting, and full test coverage.
Laravel QZ Tray is a complete silent printing solution that connects your Laravel application to desktop printers via QZ Tray. It allows you to print directly from the browser without print dialogs, with smart caching, printer memory, and automatic fallback.
统计信息
- 总下载量: 139.17k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 35
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2018-08-15