ZPL Renderer

PackagePHP

ZPL is the language that Zebra label printers speak. To see what a label looks like, you usually need the printer itself or an online service that you send your labels to. This package parses ZPL and renders it in PHP, on your own server.

One ^XA ... ^XZ format becomes one PDF page, one SVG image or one PNG image. In the PDF and the SVG, bars, boxes and barcodes stay vector shapes, so the output is sharp at every zoom level. In the PDF, text stays text. The SVG draws text as glyph outlines, so it needs no font.

A shipping label with addresses, a QR code and a Code 128 barcode

Examples

The ZPL of each example, and the SVG that the package renders from it.

shipping-label.zpl
^XA
^CI28
^PW812
^LL1218

^FX Sender
^CF0,28
^FO50,50^FDNorthvale Logistics Inc.^FS
^CF0,22
^FO50,85^FD4 Harbor Street^FS
^FO50,112^FDPortland, OR 97209^FS

^FX Divider
^FO50,150^GB712,3,3^FS

^FX Recipient
^CF0,26
^FO50,175^FDShip to^FS
^CF0,44
^FO50,210^FDBrookside Builders LLC^FS
^CF0,36
^FO50,265^FD18 Marsh Road^FS
^FO50,310^FDDenver, CO 80202^FS
^FO50,355^FDUnited States^FS

^FX Service box
^FO50,420^GB712,120,3^FS
^FO50,420^GB712,50,50^FS
^FO65,432^FR^CF0,30^FDParcel - Business^FS
^CF0,28
^FO65,485^FDWeight: 27.3 lb^FS
^FO420,485^FDPieces: 1 / 2^FS

^FX Sorting code
^FO50,570^A0N,90,90^FDCO-74^FS
^FO500,570^BQN,2,6^FDQA,https://example.com/track/00357000000000001234^FS

^FX Route barcode
^BY3,3,110
^FO50,720^BCN,110,Y,N,N^FD>;00357000000000001234^FS

^FX Footer
^FO50,900^GB712,3,3^FS
^CF0,24
^FO50,925^FB712,3,4,L,0^FDDelivered on weekdays from 8 am to 4 pm. Contact customer service if the parcel has not arrived within five business days.^FS
^FO50,1040^A0N,24,24^FDRef: ORD-2026-00918^FS
^FO50,1080^GB300,60,2^FS
^FO70,1095^A0N,30,30^FDINV 44812^FS
^FT400,1080^A0R,28,28^FDVertical^FS
^XZ
shipping-label.svg
The shipping label example rendered to SVG

Usage

composer require stilling/zpl-renderer
use Stilling\ZplRenderer\Options;
use Stilling\ZplRenderer\ZplRenderer;

$zpl = '^XA^FO50,50^A0N,40,40^FDHello^FS^FO50,120^BCN,80,Y,N,N^FD12345678^FS^XZ';
$options = new Options(dpmm: 8, widthMm: 101.6, heightMm: 152.4);

file_put_contents('label.pdf', ZplRenderer::toPdf($zpl, $options));
file_put_contents('label.svg', ZplRenderer::toSvg($zpl, $options));
file_put_contents('label.png', ZplRenderer::toPng($zpl, $options));

The package also installs a zpl command:

vendor/bin/zpl label.zpl pdf
vendor/bin/zpl label.zpl png --scale=2
cat label.zpl | vendor/bin/zpl - svg > label.svg

Coverage