Skip to content

Instantly share code, notes, and snippets.

@erighetto
Last active June 16, 2022 16:06
Show Gist options
  • Save erighetto/7080cf62b83c0851f182 to your computer and use it in GitHub Desktop.
Save erighetto/7080cf62b83c0851f182 to your computer and use it in GitHub Desktop.
Send raw ZPL to Zebra printer
<?php
error_reporting(E_ALL);
/* Get the port for the service. */
$port = "9100";
/* Get the IP address for the target host. */
$host = "172.17.144.89";
/* construct the label */
$label = "^XA ^LH0,0 ^FO4,2 ^GB804,798,4 ^FS ^FO4,2 ^GB548,52,4 ^FS ^FO19,12 ^ADN,36,20 ^FDRossi
Andrea ^FS ^FO548,2 ^GB260,52,4 ^FS ^FO561,16 ^ADN,36,10 ^FDP/V ^FS ^FO611,16
^ADN,36,10 ^FD1:3 ^FS ^FO693,16 ^ADN,36,10 ^FD18/12/14 ^FS ^FO20,66 ^GB540,135,80 ^FS
^FO21,70 ^ADN,135,25 ^FR ^FDREGGIO CALABRIA ^FS ^FO720,66 ^GB72,135,80 ^FS ^FO721,70
^ADN,135,25 ^FR ^FD13 ^FS ^FO4,210 ^GB128,166,4 ^FS ^FO128,210 ^GB680,166,4 ^FS
^FO136,220 ^ADN,36,15 ^FDProva Rossi ^FS ^FO136,276 ^ADN,36,10 ^FDCONTRADA RAVAGNESE
GRAZIELLA,8 ^FS ^FO15,243 ^ADN,108,50 ^FDE5 ^FS ^FO136,338 ^ADN,36,14 ^FDReggio
Calabria ^FS ^FO580,338 ^ADN,36,15 ^FDRC ^FS ^FO632,210 ^GB176,166,4 ^FS ^FO660,220
^AAN,18,5 ^FDCALABRIA SICILIA ^FS ^FO695,246 ^ADN,18,5 ^FDCSN ^FS ^FO632, 273
^GB176,103,4 ^FS ^FO640,280 ^ADN,18,5 ^FDPeso Kg ^FS ^FO680,318 ^ADN,36,20 ^FD4.1 ^FS
^FO632, 372 ^GB176,48,4 ^FS ^FO640,378 ^ADN,18,5 ^FDPorto: ^FS ^FO658,398 ^ADN,18,10
^FDFRANCO ^FS ^FO4,372 ^GB804,48,4 ^FS ^FO25,383 ^ADN,36,10 ^FDNote: ^FS ^FO88,383
^ADN,36,10 ^FDProva Zaffignani ^FS ^FO640,650 ^XGE:GLSMINI.GRF,1,1 ^FS ^FO606,718
^GB202,82,4 ^FS ^FO4,718 ^GB606,82,4 ^FS ^FO240,718 ^GB144,80,40 ^FS ^FO242,724
^ADN,96,25 ^FR ^FD1-25 ^FS ^FO50,422 ^BY3 ^BCN,260,N,N,N,A ^FVWW540006975010RC ^FS
^FO50,685 ^ADN,27,15 ^FDWW 540006975 01 0 RC 01 ^FS ^XZ";
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($socket === false) {
echo "socket_create() failed: reason: " . socket_strerror(socket_last_error ()) . "\n";
} else {
echo "OK.\n";
}
echo "Attempting to connect to '$host' on port '$port'...";
$result = socket_connect($socket, $host, $port);
if ($result === false) {
echo "socket_connect() failed.\nReason: ($result) " . socket_strerror (socket_last_error($socket)) . "\n";
} else {
echo "OK.\n";
}
socket_write($socket, $label, strlen($label));
socket_close($socket);
?>
@BerndSchranz
Copy link

My hero! After 6 hours of search. Great solution!

@skagamer12
Copy link

I tryied something similar, but the problems is that the printer that i will use is a shared printer from another pc, when I try to connect to the printer with $host= \192.10.10.228\ZDesigner GC420t (EPL), return The requested name is valid but no data of the requested type was found.
How can I solve it?

@daniel48saigua
Copy link

@BerndSchranz does this solution work on zebra gc420t printer?

@daniel48saigua
Copy link

@skagamer12 did it work for you on the GC420t printer?

@daniel48saigua
Copy link

@erighetto does this solution work on zebra gc420t printer?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment