PHP code example of stilling / zpl-renderer

1. Go to this page and download the library: Download stilling/zpl-renderer 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/ */

    

stilling / zpl-renderer example snippets


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);
$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));

use Stilling\ZplRenderer\Model\TextElement;

foreach (ZplRenderer::parse($zpl) as $label) {
    foreach ($label->elements as $element) {
        if ($element instanceof TextElement) {
            echo "{$element->text} at {$element->x},{$element->y}\n";
        }
    }
}

$options = (new Options())->dpmm(12)->pixelsPerDot(2)->antialias(false);
$options = new Options(dpmm: 12, pixelsPerDot: 2, antialias: false);

$base = new OptionsImmutable(dpmm: 8);
$sharp = $base->pixelsPerDot(4);   // $base still has pixelsPerDot 1