0

I know how to printer ZPL via PHP using fsockopen but I also have a few ZPL files containing the fonts and graphics used on my labels.

Can anyone tell me how to send a raw ZPL file to a printer using PHP? For now I'm using Zebranet Bridge but I prefer to be able to accomplish this from PHP.

2
  • the process for sending zpl fonts and graphics are the same as sending ZPL print jobs. Commented Jun 5, 2015 at 15:39
  • It would be if a converted font ZPL file was not encoded and readable code, but it's not. Commented Jun 8, 2015 at 7:41

1 Answer 1

4

Assuming you know how to send ZPL commands to the printer via PHP, and you want to print a font or graphic by the same means, you have to

  1. get the size of your resource and convert its binary data to an ASCII hexadecimal string:

    <?php
    $res_size = 0;
    $res_string = "";
    $res_source = "http://php.net/images/logo.php";
    $handle = fopen($res_source,"rb");
    while (!feof($handle)) {
        $data = fread($handle,1);
        $res_size++;
        $res_string .= bin2hex($data);
    }
    ?>
    
  2. compose a ZPL script to download the converted resource to printer memory:

    <?php
    require('bin2hex.php');   // script (1) above
    $zpl_download = "^XA";
    $zpl_download .= "~DYE:RES,P,P,";
    $zpl_download .= $res_size;
    $zpl_download .= ",,";
    $zpl_download .= $res_string;
    $zpl_download .= "^XZ";
    ?>
    
  3. compose a ZPL script to print the downloaded file:

    <?php
    $zpl_print = "^XA";
    $zpl_print .= "^FO50,50";
    $zpl_print .= "^IME:RES.PNG";
    $zpl_print .= "^XZ";
    ?>
    
  4. write a PHP script requiring scripts (2) and (3) above to send $zpl_download and $zpl_print to the printer.

Sign up to request clarification or add additional context in comments.

2 Comments

How do we send "ZPL commands to the printer via PHP"? I am trying $command = 'lp -h 127.0.0.1:9100 -d zpl ' . $labelcode . ' -o position=top-left,ppi=203,landscape'; $pipes = array(); $descriptors = array( 0 => array("pipe", "r"), // STDIN 1 => array("pipe", "w"), // STDOUT 2 => array("pipe", "w") // STDERR ); $process = proc_open($command, $descriptors, $pipes);
It would be great if further steps also be added, it would help others also. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.