Skip to content
Tim-MaesPublic

About

Send ZPL templates to a Zebra label printer over TCP/IP. Supports data binding and batch printing.

Resources

Stars

28 stars

Watchers

1 watching

Forks

Latest commit

 

History

57 Commits

Folders and files

Repository files navigation

PrintZPL

Description

This service allows you to discover Zebra printers and send/print ZPL templates by using HTTP POST requests.

The HTTP API requires an API key. Configure a random secret of at least 32 characters before starting the service. For example, set Security__ApiKey in the process environment (Windows PowerShell: $env:Security__ApiKey = "<random-secret>"; Linux/macOS: export Security__ApiKey="<random-secret>"). Requests must include it in the X-API-Key header. The service fails closed with HTTP 503 when no valid key is configured.

Configure Printers:AllowedAddresses with the exact printer IP addresses that this service may contact. The list is empty by default, so printing is denied until an allowlist is configured. For example, in appsettings.json:

{
  "Printers": {
    "AllowedAddresses": [ "192.168.1.30" ]
  }
}

Keep the service on a trusted network, use firewall rules to restrict callers, and do not expose the HTTP endpoint directly to the public internet. Print requests are limited to 256 KB of expanded ZPL; batches accept at most 50 items. Printer connections have a five-second timeout.

Installation

Download and run as service

Running as a Service

  1. Create the service:
sc create MyServiceName ^
    binPath= "C:\Full\Path\To\PrintZpl.exe" ^
    DisplayName= "PrintZpl" ^
    start= auto
  1. Start the service
sc start PrintZpl

The API

Discovering printers

You can send a GET request to http://localhost:9001/printers with an X-API-Key header. Example response:

[
    {
        "name": "TestPrinter",
        "ipAddress": "192.168.1.30",
        "port": 9100,
        "model": "ZebraTest"
    }
]

Print ZPL Labels

Send a POST request to http://localhost:9001/print/from-zpl with an X-API-Key header.

Using these parameters you can send a ZPL template to a printer:

{
    "ZPL": "^XA^FO50,50^ADN,36,20^FDHello, world!!^FS^XZ",
    "IpAddress": "192.168.1.30",
    "Port": 9100
}

The port defaults to 6101 when omitted. Set it explicitly to the printer's raw TCP port (commonly 9100).

Print ZPL Label with data

You can also send data parameters to process a template that has placeholders for data and specify a delimiter.

For example, if you use the $ delimiter in your ZPL template, you can send the following request:

{
    "ZPL": "^XA^FO50,50^ADN,36,20^FD$Greeting$, $Name$!^FS^XZ",
    "IpAddress": "192.168.1.30",
    "Port": 9100,
    "Data": {
        "Greeting": "Hello",
        "Name": "World"
    },
    "Delimiter": "$"
}

$Greeting$ and $Name$ will be replaced by Hello and World respectively.

Print ZPL Labels in batch

Url: http://localhost:9001/batch-print/from-zpl (include the X-API-Key header)

You can send a batch of ZPL templates to a printer by using the following request:

{
    "PrintRequests":
    [
        {
            "ZPL": "^XA^FO50,50^ADN,36,20^FDHello, $Name$!^FS^XZ",
            "IpAddress": "192.168.1.30",
            "Port": 9100,
            "Data": {
                "Name": "World",
                "Name2": "OtherValue"
            },
            "Delimiter": "$"
        },
        {
            "ZPL": "^XA^FO50,50^ADN,36,20^FDHello, $Name$!^FS^XZ",
            "IpAddress": "192.168.1.30",
            "Port": 9100,
            "Data": {
                "Name": "World",
                "Name2": "OtherValue"
            },
            "Delimiter": "$"
        }
    ]
}

The code

Building the project

Prerequisites

  • .NET 8 SDK
- dotnet build

Running the project

dotnet run

This will start a web server on port 9001.

Pack this repo code as executable

Run this command in the project folder

Windows

dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true --self-contained true

Linux

dotnet publish -r linux-x64 -c Release /p:PublishSingleFile=true --self-contained true

MacOs

dotnet publish -r osx-x64 -c Release /p:PublishSingleFile=true --self-contained true

You'll find the output .exe in bin\Release\net8.0\win-x64\publish (or the corresponding folder for your target platform).

About

Send ZPL templates to a Zebra label printer over TCP/IP. Supports data binding and batch printing.

Resources

Stars

28 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages