定制 andersonls/zpl 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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::MM or Unit::DOTS). When using Unit::MM, coordinates are converted to printer dots using the configured DPI (default 203).
  • DPI: default resolution is 203 DPI. Use setDpi() to change it or getDpi() to read it.
  • Font mapping: use setFontMapper() to provide a mapper implementing \Zpl\Fonts\AbstractMapper (the included \Zpl\Fonts\Generic maps 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 :)

paypal

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 andersonls/zpl 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 139.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 35
  • 点击次数: 20
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 35
  • Watchers: 2
  • Forks: 16
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2018-08-15