zpl

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 14 Imported by: 0

README

go-zpl

A native Go library for generating, parsing, and rendering ZPL (Zebra Programming Language) commands for thermal label printers.

Example UPS Label

Privacy

Everything runs locally - there are no servers or external API calls. The library runs in your application, the CLI processes files on your machine, and the web demo uses WebAssembly to render entirely in-browser.

Features

  • Native ZPL generation without external dependencies
  • No reliance on web services (Labelary, etc.)
  • Builder pattern for constructing labels
  • Implements standard Go interfaces (fmt.Stringer, io.WriterTo, encoding.TextMarshaler)
  • Support for common ZPL elements:
    • Text fields with fonts and positioning
    • Barcodes (Code 128, Code 39, QR codes, DataMatrix, PDF417, MaxiCode, EAN-13, UPC-A, etc.)
    • Graphics (boxes, circles, ellipses, diagonal lines)
    • Field blocks and text formatting
  • ZPL parsing - Parse existing ZPL strings into Label objects
  • Multi-page labels - Parse and render ZPL with multiple labels (e.g., USPS APO continuation sheets)
  • Local rendering - Render labels to PNG images without external services

Installation

Library
go get github.com/StirlingMarketingGroup/go-zpl
CLI Tool
go install github.com/StirlingMarketingGroup/go-zpl/cmd/zplrender@latest
Rust
[dependencies]
zpl-rs = { git = "https://github.com/StirlingMarketingGroup/go-zpl", subdirectory = "rust/zpl-rs" }
let png_bytes = zpl_rs::render("^XA^FO50,50^A0N,30,30^FDHello!^FS^XZ")?;
C/C++/Other Languages

Pre-built shared libraries (libzpl) are available for FFI integration. See releases for downloads and cmd/libzpl for documentation.

CLI Usage

# Convert ZPL file to PNG
zplrender label.zpl

# Specify output filename
zplrender -o output.png label.zpl

# Render at 300 DPI
zplrender -dpi 300 label.zpl

# Output as JPEG
zplrender -format jpeg label.zpl

# Read from stdin
cat label.zpl | zplrender -o output.png

# Show all options
zplrender -help

Quick Start

package main

import (
    "fmt"

    "github.com/StirlingMarketingGroup/go-zpl"
)

func main() {
    label := zpl.NewLabel().
        SetDPI(zpl.DPI203).
        SetSize(4, 6, zpl.UnitInches).
        TextField(50, 50, zpl.Font0, 30, 30, "Hello, World!").
        Code128(50, 150, "123456789", 100).
        QRCode(50, 300, "https://example.com", 5)

    fmt.Println(label)
}

Output:

^XA
^PW812
^LL1218
^FO50,50
^A0N,30,30
^FDHello, World!^FS
^FO50,150
^BCN,100,Y,N,N,N^FD123456789^FS
^FO50,300
^BQN,2,5^FDMA,https://example.com^FS
^XZ

API Overview

Creating Labels
// Create a new label with builder pattern
label := zpl.NewLabel().
    SetDPI(zpl.DPI203).           // Set printer DPI (203, 300, or 600)
    SetSize(4, 6, zpl.UnitInches) // Set label size
Adding Text
// Simple text field
label.TextField(x, y, zpl.Font0, height, width, "Your text")

// Text block with wrapping
label.TextBlock(x, y, zpl.Font0, height, width, blockWidth, maxLines, zpl.JustifyCenter, "Long text...")

// Using unit conversion
label.TextFieldAt(0.5, 0.5, zpl.UnitInches, zpl.Font0, 30, 30, "Text")
Adding Barcodes
// Code 128
label.Code128(x, y, "data", height)

// Code 39
label.Code39(x, y, "DATA", height)

// QR Code
label.QRCode(x, y, "data", magnification)

// DataMatrix
label.DataMatrix(x, y, "data", moduleSize)

// PDF417
label.PDF417(x, y, "data", height)

// EAN-13
label.EAN13(x, y, "5901234123457", height)

// UPC-A
label.UPCA(x, y, "012345678905", height)
Adding Graphics
// Box/Rectangle
label.Box(x, y, width, height, thickness)

// Filled box
label.FilledBox(x, y, width, height)

// Horizontal line
label.HorizontalLine(x, y, length, thickness)

// Vertical line
label.VerticalLine(x, y, length, thickness)

// Circle
label.Circle(x, y, diameter, thickness)
Low-Level API

For more control, use the command objects directly:

label.Add(zpl.NewFieldOrigin(100, 200)).
    Add(zpl.NewScalableFont(zpl.FontE, 50, 40).WithOrientation(zpl.OrientationRotated90)).
    Add(zpl.NewFieldData("Rotated Text"))
Output
// Get ZPL as string
zplString := label.String()

// Get ZPL as bytes
zplBytes := label.Bytes()

// Write to io.Writer
label.WriteTo(writer)

// Marshal as text
text, err := label.MarshalText()
Parsing ZPL
import "github.com/StirlingMarketingGroup/go-zpl"

zplString := `^XA
^FO50,50^A0N,30,30^FDHello World^FS
^FO50,100^BQN,2,5^FDMA,https://example.com^FS
^XZ`

label, err := zpl.Parse(zplString)
if err != nil {
    log.Fatal(err)
}

// Work with the parsed label
fmt.Printf("Label has %d commands\n", len(label.Commands()))

// For multi-page ZPL (multiple ^XA...^XZ blocks), use ParseAll:
labels, err := zpl.ParseAll(multiPageZPL)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Parsed %d labels\n", len(labels))
Rendering to Images
import (
    "os"
    "github.com/StirlingMarketingGroup/go-zpl"
    "github.com/StirlingMarketingGroup/go-zpl/render"
)

// Create or parse a label
label := zpl.NewLabel().
    SetDPI(zpl.DPI203).
    SetSize(4, 6, zpl.UnitInches).
    TextField(50, 50, zpl.Font0, 30, 30, "Hello, World!").
    QRCode(50, 100, "https://example.com", 5)

// Create a renderer
renderer := render.New(zpl.DPI203).WithSize(812, 1218)

// Render to PNG file
f, _ := os.Create("label.png")
defer f.Close()
renderer.RenderPNG(label, f)

Supported Commands

Label Control
  • ^XA / ^XZ - Start/end format
  • ^PW - Print width
  • ^LL - Label length
  • ^LH - Label home
  • ^PO - Print orientation
  • ^PQ - Print quantity
Text & Fonts
  • ^A - Scalable/bitmapped fonts
  • ^CF - Change default font
  • ^CI - Character set
  • ^FB - Field block (text wrapping)
  • ^FO - Field origin
  • ^FT - Field typeset
  • ^FD / ^FS - Field data / separator
  • ^FR - Field reverse
Barcodes
  • ^BC - Code 128
  • ^B3 - Code 39
  • ^BQ - QR Code
  • ^BX - DataMatrix
  • ^B7 - PDF417
  • ^BD - MaxiCode
  • ^BE - EAN-13
  • ^BU - UPC-A
  • ^B2 - Interleaved 2 of 5
  • ^BY - Barcode defaults
Graphics
  • ^GB - Graphic box
  • ^GC - Graphic circle
  • ^GD - Graphic diagonal line
  • ^GE - Graphic ellipse
  • ^GS - Graphic symbol

License

MIT

Documentation

Overview

Package zpl provides a native Go library for generating ZPL (Zebra Programming Language) commands for thermal label printers.

This is a production-grade, local replacement for services like Labelary. Rendering differences from real printers are bugs, not features.

Basic Usage

Create a label using the fluent builder API:

label := zpl.NewLabel().
	SetDPI(zpl.DPI203).
	SetSize(4, 6, zpl.UnitInches).
	TextField(50, 50, zpl.Font0, 30, 30, "Hello, World!").
	Code128(50, 150, "123456789", 100)

fmt.Println(label)

Security

When using untrusted input (e.g., user-provided text), use EscapeFieldData to prevent ZPL injection:

label.TextField(x, y, zpl.Font0, 30, 30, zpl.EscapeFieldData(userInput))

Thread Safety

Label instances are not safe for concurrent use. Create separate labels for each goroutine or use appropriate synchronization.

Index

Constants

View Source
const (
	CharSetUSA               = 0  // USA1
	CharSetUSA2              = 1  // USA2
	CharSetUK                = 2  // UK
	CharSetDutch             = 3  // Holland
	CharSetDanish            = 4  // Denmark
	CharSetSwedish           = 5  // Sweden
	CharSetGerman            = 6  // Germany
	CharSetFrench            = 7  // France1
	CharSetFrench2           = 8  // France2
	CharSetItalian           = 9  // Italy
	CharSetSpanish           = 10 // Spain
	CharSetJIS               = 12 // Japanese
	CharSetUTF8              = 28 // UTF-8
	CharSetUTF16BigEndian    = 29 // UTF-16 Big Endian
	CharSetUTF16LittleEndian = 30 // UTF-16 Little Endian
)

Common character sets.

View Source
const (
	SymbolRegisteredTrademark = 'A'
	SymbolCopyright           = 'B'
	SymbolTrademark           = 'C'
	SymbolUnderwritersLab     = 'D'
	SymbolCanadianStandards   = 'E'
)

Predefined symbols for ^GS command.

Variables

This section is empty.

Functions

func EscapeFieldData

func EscapeFieldData(s string) string

EscapeFieldData escapes special ZPL characters in field data. This prevents ZPL injection when using untrusted input.

The following characters are escaped:

  • ^ (caret) - ZPL command prefix
  • ~ (tilde) - ZPL control command prefix

Use this function when building field data from user input:

label.TextField(x, y, zpl.Font0, 30, 30, zpl.EscapeFieldData(userInput))

func GrayscaleImage

func GrayscaleImage(img image.Image) *image.Gray

GrayscaleImage converts an image to grayscale.

func MustEscapeFieldData

func MustEscapeFieldData(s string) bool

MustEscapeFieldData returns true if the string contains characters that should be escaped before use in ZPL field data.

func ResizeImage

func ResizeImage(img image.Image, maxWidth, maxHeight int) image.Image

ResizeImage resizes an image to fit within the given dimensions while maintaining aspect ratio. If maxWidth or maxHeight is 0, that dimension is not constrained.

func ToDots

func ToDots(value float64, unit Unit, dpi DPI) int

ToDots converts a measurement in the given unit to dots at the specified DPI.

Types

type BarcodeAztec

type BarcodeAztec struct {
	Orientation     Orientation
	Magnification   int  // 1-10, size of each module
	ECICEnabled     bool // Extended Channel Interpretation
	ECINumber       int  // ECI code page number
	ErrorCorrection int  // Error correction percentage (0=default, 1-99=%, 101-104=layers, 201-232=size, 300=compact)
	MenuSymbol      bool // Menu symbol (for mobile device linking)
	SymbolCount     int  // Number of symbols for structured append
	SymbolID        string
	Data            string
}

BarcodeAztec represents a ^BO command for Aztec barcodes.

func NewBarcodeAztec

func NewBarcodeAztec(data string, magnification int) *BarcodeAztec

NewBarcodeAztec creates a new Aztec barcode command.

func (*BarcodeAztec) WithErrorCorrection

func (b *BarcodeAztec) WithErrorCorrection(ec int) *BarcodeAztec

WithErrorCorrection sets the error correction level.

func (*BarcodeAztec) WithMagnification

func (b *BarcodeAztec) WithMagnification(m int) *BarcodeAztec

WithMagnification sets the magnification (module size).

func (*BarcodeAztec) WithOrientation

func (b *BarcodeAztec) WithOrientation(o Orientation) *BarcodeAztec

WithOrientation sets the Aztec barcode orientation.

func (*BarcodeAztec) WriteTo

func (b *BarcodeAztec) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeAztec) ZPL

func (b *BarcodeAztec) ZPL() string

ZPL returns the ZPL representation.

type BarcodeCode39

type BarcodeCode39 struct {
	Orientation         Orientation
	CheckDigit          bool // Mod 43 check digit
	Height              int
	PrintInterpretation bool
	InterpretationAbove bool
	Data                string
}

BarcodeCode39 represents a ^B3 command for Code 39 barcodes.

func NewBarcodeCode39

func NewBarcodeCode39(data string, height int) *BarcodeCode39

NewBarcodeCode39 creates a new Code 39 barcode command.

func (*BarcodeCode39) WithCheckDigit

func (b *BarcodeCode39) WithCheckDigit(enabled bool) *BarcodeCode39

WithCheckDigit enables Mod 43 check digit.

func (*BarcodeCode39) WithInterpretation

func (b *BarcodeCode39) WithInterpretation(printText, above bool) *BarcodeCode39

WithInterpretation sets whether to print human-readable text.

func (*BarcodeCode39) WithOrientation

func (b *BarcodeCode39) WithOrientation(o Orientation) *BarcodeCode39

WithOrientation sets the barcode orientation.

func (*BarcodeCode39) WriteTo

func (b *BarcodeCode39) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeCode39) ZPL

func (b *BarcodeCode39) ZPL() string

ZPL returns the ZPL representation.

type BarcodeCode128

type BarcodeCode128 struct {
	Orientation         Orientation
	Height              int
	PrintInterpretation bool // Print human-readable text below
	InterpretationAbove bool // Print text above barcode
	CheckDigit          bool // UCC check digit
	Mode                Code128Mode
	Data                string
}

BarcodeCode128 represents a ^BC command for Code 128 barcodes.

func NewBarcodeCode128

func NewBarcodeCode128(data string, height int) *BarcodeCode128

NewBarcodeCode128 creates a new Code 128 barcode command.

func (*BarcodeCode128) WithInterpretation

func (b *BarcodeCode128) WithInterpretation(printText, above bool) *BarcodeCode128

WithInterpretation sets whether to print human-readable text.

func (*BarcodeCode128) WithMode

func (b *BarcodeCode128) WithMode(mode Code128Mode) *BarcodeCode128

WithMode sets the Code 128 mode.

func (*BarcodeCode128) WithOrientation

func (b *BarcodeCode128) WithOrientation(o Orientation) *BarcodeCode128

WithOrientation sets the barcode orientation.

func (*BarcodeCode128) WithUCCCheckDigit

func (b *BarcodeCode128) WithUCCCheckDigit(enabled bool) *BarcodeCode128

WithUCCCheckDigit enables UCC check digit.

func (*BarcodeCode128) WriteTo

func (b *BarcodeCode128) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeCode128) ZPL

func (b *BarcodeCode128) ZPL() string

ZPL returns the ZPL representation.

type BarcodeDataMatrix

type BarcodeDataMatrix struct {
	Orientation  Orientation
	Height       int // Module size (height of individual cells)
	QualityLevel int // 0, 50, 80, 100, 140, 200
	Columns      int // Number of columns (even, 10-144)
	Rows         int // Number of rows (even, 10-144)
	FormatID     int // Format identifier
	EscapeChar   rune
	AspectRatio  int // 1 = square, 2 = rectangular
	Data         string
}

BarcodeDataMatrix represents a ^BX command for DataMatrix barcodes.

func NewBarcodeDataMatrix

func NewBarcodeDataMatrix(data string, height int) *BarcodeDataMatrix

NewBarcodeDataMatrix creates a new DataMatrix barcode command.

func (*BarcodeDataMatrix) WithOrientation

func (b *BarcodeDataMatrix) WithOrientation(o Orientation) *BarcodeDataMatrix

WithOrientation sets the DataMatrix orientation.

func (*BarcodeDataMatrix) WithQualityLevel

func (b *BarcodeDataMatrix) WithQualityLevel(level int) *BarcodeDataMatrix

WithQualityLevel sets the quality level.

func (*BarcodeDataMatrix) WithRectangular

func (b *BarcodeDataMatrix) WithRectangular() *BarcodeDataMatrix

WithRectangular sets the aspect ratio to rectangular.

func (*BarcodeDataMatrix) WithSize

func (b *BarcodeDataMatrix) WithSize(columns, rows int) *BarcodeDataMatrix

WithSize sets the explicit size (columns and rows).

func (*BarcodeDataMatrix) WriteTo

func (b *BarcodeDataMatrix) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeDataMatrix) ZPL

func (b *BarcodeDataMatrix) ZPL() string

ZPL returns the ZPL representation.

type BarcodeDefault

type BarcodeDefault struct {
	ModuleWidth       int     // Width of narrow bar in dots (1-10)
	WideToNarrowRatio float64 // Ratio of wide to narrow bars (2.0-3.0)
	Height            int     // Barcode height in dots
}

BarcodeDefault represents a ^BY command for barcode field defaults.

func NewBarcodeDefault

func NewBarcodeDefault(moduleWidth int, ratio float64, height int) *BarcodeDefault

NewBarcodeDefault creates a new barcode default command.

func (*BarcodeDefault) WriteTo

func (b *BarcodeDefault) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeDefault) ZPL

func (b *BarcodeDefault) ZPL() string

ZPL returns the ZPL representation.

type BarcodeEAN13

type BarcodeEAN13 struct {
	Orientation         Orientation
	Height              int
	PrintInterpretation bool
	InterpretationAbove bool
	Data                string
}

BarcodeEAN13 represents a ^BE command for EAN-13 barcodes.

func NewBarcodeEAN13

func NewBarcodeEAN13(data string, height int) *BarcodeEAN13

NewBarcodeEAN13 creates a new EAN-13 barcode command.

func (*BarcodeEAN13) WithInterpretation

func (b *BarcodeEAN13) WithInterpretation(printText, above bool) *BarcodeEAN13

WithInterpretation sets whether to print human-readable text.

func (*BarcodeEAN13) WithOrientation

func (b *BarcodeEAN13) WithOrientation(o Orientation) *BarcodeEAN13

WithOrientation sets the barcode orientation.

func (*BarcodeEAN13) WriteTo

func (b *BarcodeEAN13) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeEAN13) ZPL

func (b *BarcodeEAN13) ZPL() string

ZPL returns the ZPL representation.

type BarcodeInterleaved2of5

type BarcodeInterleaved2of5 struct {
	Orientation         Orientation
	Height              int
	PrintInterpretation bool
	InterpretationAbove bool
	CheckDigit          bool
	Data                string
}

BarcodeInterleaved2of5 represents a ^B2 command for Interleaved 2 of 5 barcodes.

func NewBarcodeInterleaved2of5

func NewBarcodeInterleaved2of5(data string, height int) *BarcodeInterleaved2of5

NewBarcodeInterleaved2of5 creates a new Interleaved 2 of 5 barcode command.

func (*BarcodeInterleaved2of5) WithCheckDigit

func (b *BarcodeInterleaved2of5) WithCheckDigit(enabled bool) *BarcodeInterleaved2of5

WithCheckDigit enables Mod 10 check digit.

func (*BarcodeInterleaved2of5) WithInterpretation

func (b *BarcodeInterleaved2of5) WithInterpretation(printText, above bool) *BarcodeInterleaved2of5

WithInterpretation sets whether to print human-readable text.

func (*BarcodeInterleaved2of5) WithOrientation

WithOrientation sets the barcode orientation.

func (*BarcodeInterleaved2of5) WriteTo

func (b *BarcodeInterleaved2of5) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeInterleaved2of5) ZPL

func (b *BarcodeInterleaved2of5) ZPL() string

ZPL returns the ZPL representation.

type BarcodeMaxiCode

type BarcodeMaxiCode struct {
	Mode         MaxiCodeMode
	SymbolNumber int // Symbol number for structured append (1-8)
	SymbolCount  int // Total symbols in structured append (1-8)
	Data         string
	HexIndicator rune // Character used to indicate hex values in data (e.g., '_')
}

BarcodeMaxiCode represents a ^BD command for MaxiCode 2D barcodes. MaxiCode is a fixed-size 2D barcode primarily used by UPS for package tracking.

func NewBarcodeMaxiCode

func NewBarcodeMaxiCode(data string, mode MaxiCodeMode) *BarcodeMaxiCode

NewBarcodeMaxiCode creates a new MaxiCode barcode command. Valid modes are 2-6; invalid modes default to mode 4 (standard symbol).

func (*BarcodeMaxiCode) WithHexIndicator

func (b *BarcodeMaxiCode) WithHexIndicator(indicator rune) *BarcodeMaxiCode

WithHexIndicator sets the hex escape character used in the data.

func (*BarcodeMaxiCode) WithStructuredAppend

func (b *BarcodeMaxiCode) WithStructuredAppend(symbolNumber, symbolCount int) *BarcodeMaxiCode

WithStructuredAppend sets the structured append parameters.

func (*BarcodeMaxiCode) WriteTo

func (b *BarcodeMaxiCode) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeMaxiCode) ZPL

func (b *BarcodeMaxiCode) ZPL() string

ZPL returns the ZPL representation.

type BarcodePDF417

type BarcodePDF417 struct {
	Orientation   Orientation
	Height        int
	SecurityLevel int  // 0-8
	DataColumns   int  // 1-30
	Rows          int  // 3-90
	Truncate      bool // Truncated PDF417
	Data          string
}

BarcodePDF417 represents a ^B7 command for PDF417 barcodes.

func NewBarcodePDF417

func NewBarcodePDF417(data string, height int) *BarcodePDF417

NewBarcodePDF417 creates a new PDF417 barcode command.

func (*BarcodePDF417) WithColumns

func (b *BarcodePDF417) WithColumns(columns int) *BarcodePDF417

WithColumns sets the number of data columns.

func (*BarcodePDF417) WithOrientation

func (b *BarcodePDF417) WithOrientation(o Orientation) *BarcodePDF417

WithOrientation sets the PDF417 orientation.

func (*BarcodePDF417) WithRows

func (b *BarcodePDF417) WithRows(rows int) *BarcodePDF417

WithRows sets the number of rows.

func (*BarcodePDF417) WithSecurityLevel

func (b *BarcodePDF417) WithSecurityLevel(level int) *BarcodePDF417

WithSecurityLevel sets the error correction level.

func (*BarcodePDF417) WithTruncation

func (b *BarcodePDF417) WithTruncation(truncate bool) *BarcodePDF417

WithTruncation enables truncated PDF417.

func (*BarcodePDF417) WriteTo

func (b *BarcodePDF417) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodePDF417) ZPL

func (b *BarcodePDF417) ZPL() string

ZPL returns the ZPL representation.

type BarcodeQR

type BarcodeQR struct {
	Orientation         Orientation
	Model               QRCodeModel
	MagnificationFactor int // 1-10
	ErrorCorrection     QRCodeErrorCorrection
	MaskValue           int // 0-7, typically 7 (auto)
	Data                string
}

BarcodeQR represents a ^BQ command for QR codes.

func NewBarcodeQR

func NewBarcodeQR(data string, magnification int) *BarcodeQR

NewBarcodeQR creates a new QR code command.

func (*BarcodeQR) WithErrorCorrection

func (b *BarcodeQR) WithErrorCorrection(ec QRCodeErrorCorrection) *BarcodeQR

WithErrorCorrection sets the error correction level.

func (*BarcodeQR) WithModel

func (b *BarcodeQR) WithModel(model QRCodeModel) *BarcodeQR

WithModel sets the QR code model.

func (*BarcodeQR) WithOrientation

func (b *BarcodeQR) WithOrientation(o Orientation) *BarcodeQR

WithOrientation sets the QR code orientation.

func (*BarcodeQR) WriteTo

func (b *BarcodeQR) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeQR) ZPL

func (b *BarcodeQR) ZPL() string

ZPL returns the ZPL representation.

type BarcodeUPCA

type BarcodeUPCA struct {
	Orientation         Orientation
	Height              int
	PrintInterpretation bool
	InterpretationAbove bool
	CheckDigit          bool
	Data                string
}

BarcodeUPCA represents a ^BU command for UPC-A barcodes.

func NewBarcodeUPCA

func NewBarcodeUPCA(data string, height int) *BarcodeUPCA

NewBarcodeUPCA creates a new UPC-A barcode command.

func (*BarcodeUPCA) WithCheckDigit

func (b *BarcodeUPCA) WithCheckDigit(enabled bool) *BarcodeUPCA

WithCheckDigit enables check digit printing.

func (*BarcodeUPCA) WithInterpretation

func (b *BarcodeUPCA) WithInterpretation(printText, above bool) *BarcodeUPCA

WithInterpretation sets whether to print human-readable text.

func (*BarcodeUPCA) WithOrientation

func (b *BarcodeUPCA) WithOrientation(o Orientation) *BarcodeUPCA

WithOrientation sets the barcode orientation.

func (*BarcodeUPCA) WriteTo

func (b *BarcodeUPCA) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*BarcodeUPCA) ZPL

func (b *BarcodeUPCA) ZPL() string

ZPL returns the ZPL representation.

type ChangeFont

type ChangeFont struct {
	Font   Font
	Height int
	Width  int
}

ChangeFont represents a ^CF command for changing the default font.

func NewChangeFont

func NewChangeFont(font Font, height, width int) *ChangeFont

NewChangeFont creates a new change font command.

func (*ChangeFont) WriteTo

func (f *ChangeFont) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*ChangeFont) ZPL

func (f *ChangeFont) ZPL() string

ZPL returns the ZPL representation.

type CharacterSet

type CharacterSet struct {
	CharSet int
}

CharacterSet represents a ^CI command for character set selection.

func NewCharacterSet

func NewCharacterSet(charSet int) *CharacterSet

NewCharacterSet creates a new character set command.

func (*CharacterSet) WriteTo

func (c *CharacterSet) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*CharacterSet) ZPL

func (c *CharacterSet) ZPL() string

ZPL returns the ZPL representation.

type Code128Mode

type Code128Mode rune

Code128Mode represents the Code 128 subset mode.

const (
	Code128Auto    Code128Mode = 'N' // No mode selected (defaults to Subset B)
	Code128UCC     Code128Mode = 'U' // UCC/EAN-128 mode
	Code128SubsetA Code128Mode = 'A' // Auto mode (optimizes with Subset C for numeric runs)
	Code128SubsetB Code128Mode = 'B' // Subset B explicitly
	Code128SubsetC Code128Mode = 'C' // Subset C (numeric pairs only)
	Code128SubsetD Code128Mode = 'D' // Subset D (reader programming)
)

Code 128 modes.

type Command

type Command interface {
	// ZPL returns the ZPL representation of this command.
	ZPL() string

	// WriteTo writes the ZPL representation to the given writer.
	WriteTo(w io.Writer) (int64, error)
}

Command represents a single ZPL command that can be serialized to ZPL format.

type Comment

type Comment struct {
	Text string
}

Comment represents a ^FX command for adding comments.

func NewComment

func NewComment(text string) *Comment

NewComment creates a new comment command.

func (*Comment) WriteTo

func (c *Comment) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*Comment) ZPL

func (c *Comment) ZPL() string

ZPL returns the ZPL representation.

type DPI

type DPI int

DPI represents the printer resolution in dots per inch.

const (
	// DPI203 is 203 dots per inch (8 dots/mm), the most common resolution.
	DPI203 DPI = 203
	// DPI300 is 300 dots per inch (12 dots/mm).
	DPI300 DPI = 300
	// DPI600 is 600 dots per inch (24 dots/mm).
	DPI600 DPI = 600
)

type DiagonalOrientation

type DiagonalOrientation rune

DiagonalOrientation represents the lean direction of a diagonal line.

const (
	// DiagonalRightLeaning draws from upper-left to lower-right.
	DiagonalRightLeaning DiagonalOrientation = 'R'
	// DiagonalLeftLeaning draws from lower-left to upper-right.
	DiagonalLeftLeaning DiagonalOrientation = 'L'
)

type Dithering

type Dithering int

Dithering represents the dithering algorithm to use when converting images.

const (
	// DitheringNone uses simple threshold (no dithering).
	DitheringNone Dithering = iota
	// DitheringFloydSteinberg uses Floyd-Steinberg error diffusion dithering.
	DitheringFloydSteinberg
	// DitheringOrdered uses ordered (Bayer matrix) dithering.
	DitheringOrdered
)

type FieldBlock

type FieldBlock struct {
	Width         int
	MaxLines      int
	LineSpacing   int
	Justification Justification
	HangingIndent int
}

FieldBlock represents a ^FB command for text block formatting.

func NewFieldBlock

func NewFieldBlock(width int) *FieldBlock

NewFieldBlock creates a new field block command.

func (*FieldBlock) WithHangingIndent

func (f *FieldBlock) WithHangingIndent(indent int) *FieldBlock

WithHangingIndent sets the hanging indent.

func (*FieldBlock) WithJustification

func (f *FieldBlock) WithJustification(j Justification) *FieldBlock

WithJustification sets the text justification.

func (*FieldBlock) WithLineSpacing

func (f *FieldBlock) WithLineSpacing(spacing int) *FieldBlock

WithLineSpacing sets the line spacing adjustment.

func (*FieldBlock) WithMaxLines

func (f *FieldBlock) WithMaxLines(lines int) *FieldBlock

WithMaxLines sets the maximum number of lines.

func (*FieldBlock) WriteTo

func (f *FieldBlock) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldBlock) ZPL

func (f *FieldBlock) ZPL() string

ZPL returns the ZPL representation.

type FieldData

type FieldData struct {
	Data string
}

FieldData represents a ^FD command containing field data.

func NewFieldData

func NewFieldData(data string) *FieldData

NewFieldData creates a new field data command.

func (*FieldData) WriteTo

func (f *FieldData) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldData) ZPL

func (f *FieldData) ZPL() string

ZPL returns the ZPL representation.

type FieldDirection

type FieldDirection struct {
	Orientation Orientation
}

FieldDirection represents a ^FW command for setting default field rotation. This affects all subsequent fields until changed.

func NewFieldDirection

func NewFieldDirection(orientation Orientation) *FieldDirection

NewFieldDirection creates a new field direction command.

func (*FieldDirection) WriteTo

func (f *FieldDirection) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldDirection) ZPL

func (f *FieldDirection) ZPL() string

ZPL returns the ZPL representation.

type FieldOrigin

type FieldOrigin struct {
	X, Y          int
	Justification Justification // Z = use default
}

FieldOrigin represents a ^FO command for positioning fields.

func NewFieldOrigin

func NewFieldOrigin(x, y int) *FieldOrigin

NewFieldOrigin creates a new field origin command.

func (*FieldOrigin) WithJustification

func (f *FieldOrigin) WithJustification(j Justification) *FieldOrigin

WithJustification sets the field justification.

func (*FieldOrigin) WriteTo

func (f *FieldOrigin) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldOrigin) ZPL

func (f *FieldOrigin) ZPL() string

ZPL returns the ZPL representation.

type FieldReverse

type FieldReverse struct{}

FieldReverse represents a ^FR command for reverse printing.

func NewFieldReverse

func NewFieldReverse() *FieldReverse

NewFieldReverse creates a new field reverse command.

func (*FieldReverse) WriteTo

func (f *FieldReverse) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldReverse) ZPL

func (f *FieldReverse) ZPL() string

ZPL returns the ZPL representation.

type FieldTypeset

type FieldTypeset struct {
	X, Y          int
	Justification Justification
}

FieldTypeset represents a ^FT command for baseline positioning.

func NewFieldTypeset

func NewFieldTypeset(x, y int) *FieldTypeset

NewFieldTypeset creates a new field typeset command.

func (*FieldTypeset) WithJustification

func (f *FieldTypeset) WithJustification(j Justification) *FieldTypeset

WithJustification sets the field justification.

func (*FieldTypeset) WriteTo

func (f *FieldTypeset) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*FieldTypeset) ZPL

func (f *FieldTypeset) ZPL() string

ZPL returns the ZPL representation.

type Font

type Font rune

Font represents a ZPL font identifier.

const (
	FontA Font = 'A' // 9x5 matrix
	FontB Font = 'B' // 11x7 matrix
	FontC Font = 'C' // 18x10 matrix
	FontD Font = 'D' // 18x10 matrix
	FontE Font = 'E' // 28x15 matrix (OCR-B)
	FontF Font = 'F' // 26x13 matrix
	FontG Font = 'G' // 60x40 matrix
	FontH Font = 'H' // 21x13 matrix (OCR-A)
	Font0 Font = '0' // 15x12 matrix (default)

	// Additional fonts
	FontP Font = 'P' // Standard font
	FontQ Font = 'Q' // Standard font
	FontR Font = 'R' // Standard font
	FontS Font = 'S' // Standard font (also used as symbol font)
	FontT Font = 'T' // Standard font
	FontU Font = 'U' // Standard font
	FontV Font = 'V' // Standard font
)

Built-in ZPL fonts.

type GraphicBox

type GraphicBox struct {
	Width        int
	Height       int
	Thickness    int
	Color        LineColor
	CornerRadius int
}

GraphicBox represents a ^GB command for drawing boxes/rectangles.

func NewGraphicBox

func NewGraphicBox(width, height, thickness int) *GraphicBox

NewGraphicBox creates a new graphic box command.

func (*GraphicBox) WithColor

func (g *GraphicBox) WithColor(color LineColor) *GraphicBox

WithColor sets the line color.

func (*GraphicBox) WithCornerRadius

func (g *GraphicBox) WithCornerRadius(radius int) *GraphicBox

WithCornerRadius sets the corner rounding radius.

func (*GraphicBox) WriteTo

func (g *GraphicBox) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicBox) ZPL

func (g *GraphicBox) ZPL() string

ZPL returns the ZPL representation.

type GraphicCircle

type GraphicCircle struct {
	Diameter  int
	Thickness int
	Color     LineColor
}

GraphicCircle represents a ^GC command for drawing circles.

func NewGraphicCircle

func NewGraphicCircle(diameter, thickness int) *GraphicCircle

NewGraphicCircle creates a new graphic circle command.

func (*GraphicCircle) WithColor

func (g *GraphicCircle) WithColor(color LineColor) *GraphicCircle

WithColor sets the line color.

func (*GraphicCircle) WriteTo

func (g *GraphicCircle) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicCircle) ZPL

func (g *GraphicCircle) ZPL() string

ZPL returns the ZPL representation.

type GraphicDiagonalLine

type GraphicDiagonalLine struct {
	Width       int
	Height      int
	Thickness   int
	Color       LineColor
	Orientation DiagonalOrientation
}

GraphicDiagonalLine represents a ^GD command for drawing diagonal lines.

func NewGraphicDiagonalLine

func NewGraphicDiagonalLine(width, height, thickness int) *GraphicDiagonalLine

NewGraphicDiagonalLine creates a new graphic diagonal line command.

func (*GraphicDiagonalLine) WithColor

func (g *GraphicDiagonalLine) WithColor(color LineColor) *GraphicDiagonalLine

WithColor sets the line color.

func (*GraphicDiagonalLine) WithLeftLeaning

func (g *GraphicDiagonalLine) WithLeftLeaning() *GraphicDiagonalLine

WithLeftLeaning sets the diagonal to lean left.

func (*GraphicDiagonalLine) WithRightLeaning

func (g *GraphicDiagonalLine) WithRightLeaning() *GraphicDiagonalLine

WithRightLeaning sets the diagonal to lean right.

func (*GraphicDiagonalLine) WriteTo

func (g *GraphicDiagonalLine) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicDiagonalLine) ZPL

func (g *GraphicDiagonalLine) ZPL() string

ZPL returns the ZPL representation.

type GraphicEllipse

type GraphicEllipse struct {
	Width     int
	Height    int
	Thickness int
	Color     LineColor
}

GraphicEllipse represents a ^GE command for drawing ellipses.

func NewGraphicEllipse

func NewGraphicEllipse(width, height, thickness int) *GraphicEllipse

NewGraphicEllipse creates a new graphic ellipse command.

func (*GraphicEllipse) WithColor

func (g *GraphicEllipse) WithColor(color LineColor) *GraphicEllipse

WithColor sets the line color.

func (*GraphicEllipse) WriteTo

func (g *GraphicEllipse) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicEllipse) ZPL

func (g *GraphicEllipse) ZPL() string

ZPL returns the ZPL representation.

type GraphicField

type GraphicField struct {
	Format      GraphicFieldFormat
	DataBytes   int    // Total bytes in the data
	TotalBytes  int    // Total bytes comprising the graphic
	BytesPerRow int    // Number of bytes per row
	Data        string // Hex data (for ASCII format)
	BinaryData  []byte // Binary data (for binary format)
}

GraphicField represents a ^GF command for embedding bitmap graphics.

func ImageToGraphicField

func ImageToGraphicField(img image.Image) *GraphicField

ImageToGraphicField is a convenience function that converts an image to a GraphicField using default settings (threshold 128, no dithering).

func ImageToGraphicFieldDithered

func ImageToGraphicFieldDithered(img image.Image) *GraphicField

ImageToGraphicFieldDithered converts an image to a GraphicField using Floyd-Steinberg dithering.

func ImageToGraphicFieldZ64

func ImageToGraphicFieldZ64(img image.Image) *GraphicField

ImageToGraphicFieldZ64 converts an image to a GraphicField using Z64 compression.

func NewGraphicFieldASCII

func NewGraphicFieldASCII(bytesPerRow int, data string) *GraphicField

NewGraphicFieldASCII creates a new graphic field with ASCII hex data.

func NewGraphicFieldBinary

func NewGraphicFieldBinary(bytesPerRow int, data []byte) *GraphicField

NewGraphicFieldBinary creates a new graphic field with binary data.

func (*GraphicField) WriteTo

func (g *GraphicField) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicField) ZPL

func (g *GraphicField) ZPL() string

ZPL returns the ZPL representation.

type GraphicFieldFormat

type GraphicFieldFormat rune

GraphicFieldFormat represents the compression format for ^GF commands.

const (
	// GraphicFieldASCII is ASCII hexadecimal format (^GFA).
	GraphicFieldASCII GraphicFieldFormat = 'A'
	// GraphicFieldBinary is binary format (^GFB).
	GraphicFieldBinary GraphicFieldFormat = 'B'
	// GraphicFieldCompressed is compressed binary format (^GFC).
	GraphicFieldCompressed GraphicFieldFormat = 'C'
)

type GraphicSymbol

type GraphicSymbol struct {
	Orientation Orientation
	Height      int
	Width       int
	Symbol      rune
}

GraphicSymbol represents a ^GS command for printing symbols.

func NewGraphicSymbol

func NewGraphicSymbol(symbol rune, height, width int) *GraphicSymbol

NewGraphicSymbol creates a new graphic symbol command.

func (*GraphicSymbol) WithOrientation

func (g *GraphicSymbol) WithOrientation(o Orientation) *GraphicSymbol

WithOrientation sets the symbol orientation.

func (*GraphicSymbol) WriteTo

func (g *GraphicSymbol) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*GraphicSymbol) ZPL

func (g *GraphicSymbol) ZPL() string

ZPL returns the ZPL representation.

type ImageConverter

type ImageConverter struct {
	// Threshold is the grayscale cutoff (0-255) for black/white conversion.
	// Pixels darker than this become black. Default is 128.
	Threshold uint8

	// Dithering specifies the dithering algorithm to use.
	Dithering Dithering

	// Invert swaps black and white in the output.
	Invert bool
}

ImageConverter converts images to ZPL graphic fields.

func NewImageConverter

func NewImageConverter() *ImageConverter

NewImageConverter creates a new image converter with default settings.

func (*ImageConverter) Convert

func (c *ImageConverter) Convert(img image.Image) *GraphicField

Convert converts an image to a ZPL GraphicField. The image is converted to 1-bit monochrome using the configured dithering.

func (*ImageConverter) ConvertBinary

func (c *ImageConverter) ConvertBinary(img image.Image) *GraphicField

ConvertBinary converts an image to a ZPL GraphicField using binary format. Binary format is more compact than ASCII hex.

func (*ImageConverter) ConvertReader

func (c *ImageConverter) ConvertReader(r io.Reader) (*GraphicField, error)

ConvertReader reads an image from a reader and converts it to a GraphicField.

func (*ImageConverter) ConvertZ64

func (c *ImageConverter) ConvertZ64(img image.Image) *GraphicField

ConvertZ64 converts an image to a ZPL GraphicField using Z64 compression. Z64 is base64-encoded zlib-compressed data, which is typically much smaller than ASCII hex format for complex images.

func (*ImageConverter) WithDithering

func (c *ImageConverter) WithDithering(d Dithering) *ImageConverter

WithDithering sets the dithering algorithm.

func (*ImageConverter) WithInvert

func (c *ImageConverter) WithInvert(invert bool) *ImageConverter

WithInvert sets whether to invert the output.

func (*ImageConverter) WithThreshold

func (c *ImageConverter) WithThreshold(t uint8) *ImageConverter

WithThreshold sets the black/white threshold (0-255).

type Justification

type Justification rune

Justification represents text justification in field blocks.

const (
	// JustifyLeft aligns text to the left.
	JustifyLeft Justification = 'L'
	// JustifyCenter centers the text.
	JustifyCenter Justification = 'C'
	// JustifyRight aligns text to the right.
	JustifyRight Justification = 'R'
	// JustifyJustified stretches text to fill the width.
	JustifyJustified Justification = 'J'
)

type Label

type Label struct {
	// contains filtered or unexported fields
}

Label represents a ZPL label with all its commands. It implements fmt.Stringer, io.WriterTo, and encoding.TextMarshaler.

A Label is not safe for concurrent use.

func NewLabel

func NewLabel() *Label

NewLabel creates a new empty label with default settings.

func Parse

func Parse(zpl string) (*Label, error)

Parse parses a ZPL string and returns the first Label. For ZPL with multiple labels (multiple ^XA...^XZ blocks), use ParseAll.

func ParseAll

func ParseAll(zpl string) ([]*Label, error)

ParseAll parses a ZPL string and returns all labels (one per ^XA...^XZ block).

func (*Label) Add

func (l *Label) Add(cmd Command) *Label

Add appends a command to the label. Panics if cmd is nil.

func (*Label) AddAll

func (l *Label) AddAll(cmds ...Command) *Label

AddAll appends multiple commands to the label. Panics if any command is nil.

func (*Label) Box

func (l *Label) Box(x, y, width, height, thickness int) *Label

Box adds a graphic box at the specified position.

func (*Label) BoxAt

func (l *Label) BoxAt(x, y, width, height float64, unit Unit, thickness int) *Label

BoxAt adds a graphic box using unit conversion.

func (*Label) Bytes

func (l *Label) Bytes() []byte

Bytes returns the ZPL code as a byte slice.

func (*Label) Circle

func (l *Label) Circle(x, y, diameter, thickness int) *Label

Circle adds a circle at the specified position.

func (*Label) Code39

func (l *Label) Code39(x, y int, data string, height int) *Label

Code39 adds a Code 39 barcode at the specified position.

func (*Label) Code128

func (l *Label) Code128(x, y int, data string, height int) *Label

Code128 adds a Code 128 barcode at the specified position.

func (*Label) Code128At

func (l *Label) Code128At(x, y float64, unit Unit, data string, height int) *Label

Code128At adds a Code 128 barcode using unit conversion.

func (*Label) Commands

func (l *Label) Commands() []Command

Commands returns a copy of the label's commands.

func (*Label) Comment

func (l *Label) Comment(text string) *Label

Comment adds a comment to the ZPL (not printed, for documentation).

func (*Label) DPISetting

func (l *Label) DPISetting() DPI

DPISetting returns the configured DPI.

func (*Label) DataMatrix

func (l *Label) DataMatrix(x, y int, data string, moduleSize int) *Label

DataMatrix adds a DataMatrix barcode at the specified position.

func (*Label) EAN13

func (l *Label) EAN13(x, y int, data string, height int) *Label

EAN13 adds an EAN-13 barcode at the specified position.

func (*Label) FilledBox

func (l *Label) FilledBox(x, y, width, height int) *Label

FilledBox adds a filled graphic box at the specified position.

func (*Label) Height

func (l *Label) Height() int

Height returns the label height in dots.

func (*Label) Home

func (l *Label) Home() (x, y int)

Home returns the label home offset in dots (^LH).

func (*Label) HorizontalLine

func (l *Label) HorizontalLine(x, y, length, thickness int) *Label

HorizontalLine adds a horizontal line at the specified position.

func (*Label) MarshalText

func (l *Label) MarshalText() ([]byte, error)

MarshalText returns the ZPL code as a byte slice. Implements encoding.TextMarshaler.

func (*Label) PDF417

func (l *Label) PDF417(x, y int, data string, height int) *Label

PDF417 adds a PDF417 barcode at the specified position.

func (*Label) PrintOrientationSetting

func (l *Label) PrintOrientationSetting() PrintOrientation

PrintOrientationSetting returns the configured print orientation.

func (*Label) PrintQuantity

func (l *Label) PrintQuantity() int

PrintQuantity returns the print quantity (^PQ) - how many copies to print.

func (*Label) QRCode

func (l *Label) QRCode(x, y int, data string, magnification int) *Label

QRCode adds a QR code at the specified position.

func (*Label) QRCodeAt

func (l *Label) QRCodeAt(x, y float64, unit Unit, data string, magnification int) *Label

QRCodeAt adds a QR code using unit conversion.

func (*Label) ReverseField

func (l *Label) ReverseField() *Label

ReverseField enables reverse printing for the next field.

func (*Label) SetBarcodeDefaults

func (l *Label) SetBarcodeDefaults(moduleWidth int, ratio float64, height int) *Label

SetBarcodeDefaults sets the default barcode parameters.

func (*Label) SetCharacterSet

func (l *Label) SetCharacterSet(charSet int) *Label

SetCharacterSet sets the character encoding.

func (*Label) SetDPI

func (l *Label) SetDPI(dpi DPI) *Label

SetDPI sets the printer DPI for unit conversions.

func (*Label) SetDefaultFont

func (l *Label) SetDefaultFont(font Font, height, width int) *Label

SetDefaultFont sets the default font for subsequent text fields.

func (*Label) SetHome

func (l *Label) SetHome(x, y float64, unit Unit) *Label

SetHome sets the label home position (^LH).

func (*Label) SetHomeDots

func (l *Label) SetHomeDots(x, y int) *Label

SetHomeDots sets the label home position in dots (^LH).

func (*Label) SetPrintOrientation

func (l *Label) SetPrintOrientation(orientation PrintOrientation) *Label

SetPrintOrientation sets the print orientation (^PO).

func (*Label) SetPrintQuantity

func (l *Label) SetPrintQuantity(quantity, pauseAndCut, replicates int, overridePause bool) *Label

SetPrintQuantity sets the print quantity (^PQ). quantity: total number of labels to print pauseAndCut: pause and cut after this many labels (0 = no pause) replicates: number of replicates of each serial number overridePause: override pause count ('Y' or 'N')

func (*Label) SetSize

func (l *Label) SetSize(width, height float64, unit Unit) *Label

SetSize sets the label dimensions.

func (*Label) SetSizeDots

func (l *Label) SetSizeDots(width, height int) *Label

SetSizeDots sets the label dimensions in dots.

func (*Label) String

func (l *Label) String() string

String returns the complete ZPL code for this label. Implements fmt.Stringer.

func (*Label) TextBlock

func (l *Label) TextBlock(x, y int, font Font, height, width, blockWidth, maxLines int, justify Justification, data string) *Label

TextBlock adds a text block with wrapping at the specified position.

func (*Label) TextField

func (l *Label) TextField(x, y int, font Font, height, width int, data string) *Label

TextField is a convenience method to add positioned text to the label.

func (*Label) TextFieldAt

func (l *Label) TextFieldAt(x, y float64, unit Unit, font Font, height, width int, data string) *Label

TextFieldAt is a convenience method using unit conversion.

func (*Label) UPCA

func (l *Label) UPCA(x, y int, data string, height int) *Label

UPCA adds a UPC-A barcode at the specified position.

func (*Label) VerticalLine

func (l *Label) VerticalLine(x, y, length, thickness int) *Label

VerticalLine adds a vertical line at the specified position.

func (*Label) Width

func (l *Label) Width() int

Width returns the label width in dots.

func (*Label) WriteTo

func (l *Label) WriteTo(w io.Writer) (int64, error)

WriteTo writes the complete ZPL code to the given writer. Implements io.WriterTo.

func (*Label) ZPL

func (l *Label) ZPL() string

ZPL returns the complete ZPL code for this label. This is an alias for String() for API consistency.

type LineColor

type LineColor rune

LineColor represents the color of lines and shapes.

const (
	// LineColorBlack draws in black.
	LineColorBlack LineColor = 'B'
	// LineColorWhite draws in white (erases).
	LineColorWhite LineColor = 'W'
)

type MaxiCodeMode

type MaxiCodeMode int

MaxiCodeMode represents the MaxiCode encoding mode.

const (
	MaxiCodeMode2 MaxiCodeMode = 2 // Structured Carrier Message (US)
	MaxiCodeMode3 MaxiCodeMode = 3 // Structured Carrier Message (International)
	MaxiCodeMode4 MaxiCodeMode = 4 // Standard Symbol (full ECC)
	MaxiCodeMode5 MaxiCodeMode = 5 // Full ECC (secure data)
	MaxiCodeMode6 MaxiCodeMode = 6 // Reader Programming
)

MaxiCode modes.

type Orientation

type Orientation rune

Orientation represents the rotation of an element.

const (
	// OrientationNormal is 0° rotation (normal).
	OrientationNormal Orientation = 'N'
	// OrientationRotated90 is 90° clockwise rotation.
	OrientationRotated90 Orientation = 'R'
	// OrientationRotated180 is 180° rotation (inverted).
	OrientationRotated180 Orientation = 'I'
	// OrientationRotated270 is 270° clockwise rotation.
	OrientationRotated270 Orientation = 'B'
)

type PrintOrientation

type PrintOrientation rune

PrintOrientation represents the label print orientation.

const (
	// PrintOrientationNormal prints the label normally.
	PrintOrientationNormal PrintOrientation = 'N'
	// PrintOrientationInverted prints the label inverted (180°).
	PrintOrientationInverted PrintOrientation = 'I'
)

type QRCodeErrorCorrection

type QRCodeErrorCorrection rune

QRCodeErrorCorrection represents the error correction level.

const (
	QRCodeECHigh     QRCodeErrorCorrection = 'H' // ~30% recovery
	QRCodeECQuartile QRCodeErrorCorrection = 'Q' // ~25% recovery
	QRCodeECMedium   QRCodeErrorCorrection = 'M' // ~15% recovery
	QRCodeECLow      QRCodeErrorCorrection = 'L' // ~7% recovery
)

QR code error correction levels.

type QRCodeModel

type QRCodeModel int

QRCodeModel represents the QR code model.

const (
	QRCodeModel1 QRCodeModel = 1
	QRCodeModel2 QRCodeModel = 2 // Recommended
)

QR code models.

type ScalableFont

type ScalableFont struct {
	Font        Font
	Orientation Orientation
	Height      int // Character height in dots
	Width       int // Character width in dots (0 = proportional)
}

ScalableFont represents a ^A command for selecting a font.

func NewScalableFont

func NewScalableFont(font Font, height, width int) *ScalableFont

NewScalableFont creates a new font selection command.

func (*ScalableFont) WithOrientation

func (f *ScalableFont) WithOrientation(o Orientation) *ScalableFont

WithOrientation sets the font orientation.

func (*ScalableFont) WriteTo

func (f *ScalableFont) WriteTo(w io.Writer) (int64, error)

WriteTo writes the ZPL to the writer.

func (*ScalableFont) ZPL

func (f *ScalableFont) ZPL() string

ZPL returns the ZPL representation.

type Unit

type Unit int

Unit represents a unit of measurement.

const (
	// UnitDots represents raw printer dots.
	UnitDots Unit = iota
	// UnitInches represents inches.
	UnitInches
	// UnitMillimeters represents millimeters.
	UnitMillimeters
	// UnitCentimeters represents centimeters.
	UnitCentimeters
)

Directories

Path Synopsis
cmd
libzpl command
Package main provides a C shared library for ZPL rendering.
Package main provides a C shared library for ZPL rendering.
zplprint command
zplprint sends ZPL files directly to a USB Zebra printer on macOS
zplprint sends ZPL files directly to a USB Zebra printer on macOS
zplrender command
zplrender converts ZPL files to images
zplrender converts ZPL files to images
examples
basic command
Package main demonstrates basic usage of the go-zpl library.
Package main demonstrates basic usage of the go-zpl library.
fonts command
Example demonstrating different fonts in the render package.
Example demonstrating different fonts in the render package.
glyph_preview command
Preview the glyph chart ZPL files using our renderer
Preview the glyph chart ZPL files using our renderer
render command
Example demonstrating the render package for converting ZPL labels to images.
Example demonstrating the render package for converting ZPL labels to images.
internal
maxicode
Package maxicode implements MaxiCode 2D barcode encoding.
Package maxicode implements MaxiCode 2D barcode encoding.
maxicode/readsolomon
Package readsolomon implements Reed-Solomon error correction for MaxiCode.
Package readsolomon implements Reed-Solomon error correction for MaxiCode.
pdf417
Code derived from github.com/boombuler/barcode/pdf417 (MIT License).
Code derived from github.com/boombuler/barcode/pdf417 (MIT License).
Package render provides image rendering capabilities for ZPL labels.
Package render provides image rendering capabilities for ZPL labels.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL