DEV Community

labelixa
labelixa

Posted on Originally published at labelixa.com

Send raw ZPL to a Zebra printer with zero drivers (port 9100)

A ZPL file does not need a driver to be printed. Most networked thermal
printers listen on TCP port 9100 ("raw" / "JetDirect" printing) and
treat everything that arrives there as printer commands. Printing a
label is just moving bytes to a socket.

Linux / macOS

nc 192.168.1.50 9100 < label.zpl
Enter fullscreen mode Exit fullscreen mode

That's it. netcat, no CUPS queue, nothing to configure.

Windows

PowerShell opens the same socket without extra tools:

$c = New-Object Net.Sockets.TcpClient('192.168.1.50', 9100)
$b = [IO.File]::ReadAllBytes('label.zpl')
$c.GetStream().Write($b, 0, $b.Length); $c.Close()
Enter fullscreen mode Exit fullscreen mode

From code

Any language with TCP sockets can print. Python:

import socket

with socket.create_connection(("192.168.1.50", 9100), timeout=5) as s:
    with open("label.zpl", "rb") as f:
        s.sendall(f.read())
Enter fullscreen mode Exit fullscreen mode

The catch: 9100 gives you no feedback

There is no response protocol in the simple case. The socket closing
without an error means the printer accepted the bytes — not that
the label printed correctly. Density mismatches and layout bugs are
invisible here. So preview first: paste the ZPL into an
online viewer (disclosure: I
work on Labelixa) and catch the missing ^FS before the printer does.
Port 9100 has no undo; every mistake costs a label and ribbon.

When nothing prints, in order

  1. ping the printer — if that fails it's a network problem, not ZPL.
  2. Is 9100 open? Some printers ship with raw printing disabled or on another port — check the printer's network config page.
  3. Paused or in an error state? A blinking light means the job is queued inside the printer, not lost.
  4. Is the ZPL actually a label? Everything must sit between ^XA and ^XZ — a file without that frame is silently ignored (the #1 "it does nothing" cause).
  5. Prints, but wrongly? Different problem class — that one is about density, ^FS and clipping.

Top comments (0)