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
- func EscapeFieldData(s string) string
- func GrayscaleImage(img image.Image) *image.Gray
- func MustEscapeFieldData(s string) bool
- func ResizeImage(img image.Image, maxWidth, maxHeight int) image.Image
- func ToDots(value float64, unit Unit, dpi DPI) int
- type BarcodeAztec
- type BarcodeCode39
- func (b *BarcodeCode39) WithCheckDigit(enabled bool) *BarcodeCode39
- func (b *BarcodeCode39) WithInterpretation(printText, above bool) *BarcodeCode39
- func (b *BarcodeCode39) WithOrientation(o Orientation) *BarcodeCode39
- func (b *BarcodeCode39) WriteTo(w io.Writer) (int64, error)
- func (b *BarcodeCode39) ZPL() string
- type BarcodeCode128
- func (b *BarcodeCode128) WithInterpretation(printText, above bool) *BarcodeCode128
- func (b *BarcodeCode128) WithMode(mode Code128Mode) *BarcodeCode128
- func (b *BarcodeCode128) WithOrientation(o Orientation) *BarcodeCode128
- func (b *BarcodeCode128) WithUCCCheckDigit(enabled bool) *BarcodeCode128
- func (b *BarcodeCode128) WriteTo(w io.Writer) (int64, error)
- func (b *BarcodeCode128) ZPL() string
- type BarcodeDataMatrix
- func (b *BarcodeDataMatrix) WithOrientation(o Orientation) *BarcodeDataMatrix
- func (b *BarcodeDataMatrix) WithQualityLevel(level int) *BarcodeDataMatrix
- func (b *BarcodeDataMatrix) WithRectangular() *BarcodeDataMatrix
- func (b *BarcodeDataMatrix) WithSize(columns, rows int) *BarcodeDataMatrix
- func (b *BarcodeDataMatrix) WriteTo(w io.Writer) (int64, error)
- func (b *BarcodeDataMatrix) ZPL() string
- type BarcodeDefault
- type BarcodeEAN13
- type BarcodeInterleaved2of5
- func (b *BarcodeInterleaved2of5) WithCheckDigit(enabled bool) *BarcodeInterleaved2of5
- func (b *BarcodeInterleaved2of5) WithInterpretation(printText, above bool) *BarcodeInterleaved2of5
- func (b *BarcodeInterleaved2of5) WithOrientation(o Orientation) *BarcodeInterleaved2of5
- func (b *BarcodeInterleaved2of5) WriteTo(w io.Writer) (int64, error)
- func (b *BarcodeInterleaved2of5) ZPL() string
- type BarcodeMaxiCode
- type BarcodePDF417
- func (b *BarcodePDF417) WithColumns(columns int) *BarcodePDF417
- func (b *BarcodePDF417) WithOrientation(o Orientation) *BarcodePDF417
- func (b *BarcodePDF417) WithRows(rows int) *BarcodePDF417
- func (b *BarcodePDF417) WithSecurityLevel(level int) *BarcodePDF417
- func (b *BarcodePDF417) WithTruncation(truncate bool) *BarcodePDF417
- func (b *BarcodePDF417) WriteTo(w io.Writer) (int64, error)
- func (b *BarcodePDF417) ZPL() string
- type BarcodeQR
- type BarcodeUPCA
- type ChangeFont
- type CharacterSet
- type Code128Mode
- type Command
- type Comment
- type DPI
- type DiagonalOrientation
- type Dithering
- type FieldBlock
- func (f *FieldBlock) WithHangingIndent(indent int) *FieldBlock
- func (f *FieldBlock) WithJustification(j Justification) *FieldBlock
- func (f *FieldBlock) WithLineSpacing(spacing int) *FieldBlock
- func (f *FieldBlock) WithMaxLines(lines int) *FieldBlock
- func (f *FieldBlock) WriteTo(w io.Writer) (int64, error)
- func (f *FieldBlock) ZPL() string
- type FieldData
- type FieldDirection
- type FieldOrigin
- type FieldReverse
- type FieldTypeset
- type Font
- type GraphicBox
- type GraphicCircle
- type GraphicDiagonalLine
- func (g *GraphicDiagonalLine) WithColor(color LineColor) *GraphicDiagonalLine
- func (g *GraphicDiagonalLine) WithLeftLeaning() *GraphicDiagonalLine
- func (g *GraphicDiagonalLine) WithRightLeaning() *GraphicDiagonalLine
- func (g *GraphicDiagonalLine) WriteTo(w io.Writer) (int64, error)
- func (g *GraphicDiagonalLine) ZPL() string
- type GraphicEllipse
- type GraphicField
- func ImageToGraphicField(img image.Image) *GraphicField
- func ImageToGraphicFieldDithered(img image.Image) *GraphicField
- func ImageToGraphicFieldZ64(img image.Image) *GraphicField
- func NewGraphicFieldASCII(bytesPerRow int, data string) *GraphicField
- func NewGraphicFieldBinary(bytesPerRow int, data []byte) *GraphicField
- type GraphicFieldFormat
- type GraphicSymbol
- type ImageConverter
- func (c *ImageConverter) Convert(img image.Image) *GraphicField
- func (c *ImageConverter) ConvertBinary(img image.Image) *GraphicField
- func (c *ImageConverter) ConvertReader(r io.Reader) (*GraphicField, error)
- func (c *ImageConverter) ConvertZ64(img image.Image) *GraphicField
- func (c *ImageConverter) WithDithering(d Dithering) *ImageConverter
- func (c *ImageConverter) WithInvert(invert bool) *ImageConverter
- func (c *ImageConverter) WithThreshold(t uint8) *ImageConverter
- type Justification
- type Label
- func (l *Label) Add(cmd Command) *Label
- func (l *Label) AddAll(cmds ...Command) *Label
- func (l *Label) Box(x, y, width, height, thickness int) *Label
- func (l *Label) BoxAt(x, y, width, height float64, unit Unit, thickness int) *Label
- func (l *Label) Bytes() []byte
- func (l *Label) Circle(x, y, diameter, thickness int) *Label
- func (l *Label) Code39(x, y int, data string, height int) *Label
- func (l *Label) Code128(x, y int, data string, height int) *Label
- func (l *Label) Code128At(x, y float64, unit Unit, data string, height int) *Label
- func (l *Label) Commands() []Command
- func (l *Label) Comment(text string) *Label
- func (l *Label) DPISetting() DPI
- func (l *Label) DataMatrix(x, y int, data string, moduleSize int) *Label
- func (l *Label) EAN13(x, y int, data string, height int) *Label
- func (l *Label) FilledBox(x, y, width, height int) *Label
- func (l *Label) Height() int
- func (l *Label) Home() (x, y int)
- func (l *Label) HorizontalLine(x, y, length, thickness int) *Label
- func (l *Label) MarshalText() ([]byte, error)
- func (l *Label) PDF417(x, y int, data string, height int) *Label
- func (l *Label) PrintOrientationSetting() PrintOrientation
- func (l *Label) PrintQuantity() int
- func (l *Label) QRCode(x, y int, data string, magnification int) *Label
- func (l *Label) QRCodeAt(x, y float64, unit Unit, data string, magnification int) *Label
- func (l *Label) ReverseField() *Label
- func (l *Label) SetBarcodeDefaults(moduleWidth int, ratio float64, height int) *Label
- func (l *Label) SetCharacterSet(charSet int) *Label
- func (l *Label) SetDPI(dpi DPI) *Label
- func (l *Label) SetDefaultFont(font Font, height, width int) *Label
- func (l *Label) SetHome(x, y float64, unit Unit) *Label
- func (l *Label) SetHomeDots(x, y int) *Label
- func (l *Label) SetPrintOrientation(orientation PrintOrientation) *Label
- func (l *Label) SetPrintQuantity(quantity, pauseAndCut, replicates int, overridePause bool) *Label
- func (l *Label) SetSize(width, height float64, unit Unit) *Label
- func (l *Label) SetSizeDots(width, height int) *Label
- func (l *Label) String() string
- func (l *Label) TextBlock(x, y int, font Font, height, width, blockWidth, maxLines int, ...) *Label
- func (l *Label) TextField(x, y int, font Font, height, width int, data string) *Label
- func (l *Label) TextFieldAt(x, y float64, unit Unit, font Font, height, width int, data string) *Label
- func (l *Label) UPCA(x, y int, data string, height int) *Label
- func (l *Label) VerticalLine(x, y, length, thickness int) *Label
- func (l *Label) Width() int
- func (l *Label) WriteTo(w io.Writer) (int64, error)
- func (l *Label) ZPL() string
- type LineColor
- type MaxiCodeMode
- type Orientation
- type PrintOrientation
- type QRCodeErrorCorrection
- type QRCodeModel
- type ScalableFont
- type Unit
Constants ¶
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.
const ( SymbolRegisteredTrademark = 'A' SymbolCopyright = 'B' SymbolTrademark = 'C' SymbolUnderwritersLab = 'D' SymbolCanadianStandards = 'E' )
Predefined symbols for ^GS command.
Variables ¶
This section is empty.
Functions ¶
func EscapeFieldData ¶
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 ¶
GrayscaleImage converts an image to grayscale.
func MustEscapeFieldData ¶
MustEscapeFieldData returns true if the string contains characters that should be escaped before use in ZPL field data.
func ResizeImage ¶
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.
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.
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.
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 ¶
func (b *BarcodeInterleaved2of5) WithOrientation(o Orientation) *BarcodeInterleaved2of5
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 ¶
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.
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.
type ChangeFont ¶
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.
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.
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.
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.
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.
type FieldData ¶
type FieldData struct {
Data string
}
FieldData represents a ^FD command containing field data.
func NewFieldData ¶
NewFieldData creates a new field data command.
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.
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.
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.
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 ¶
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.
type GraphicCircle ¶
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 ¶
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.
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 Parse ¶
Parse parses a ZPL string and returns the first Label. For ZPL with multiple labels (multiple ^XA...^XZ blocks), use ParseAll.
func (*Label) DataMatrix ¶
DataMatrix adds a DataMatrix barcode at the specified position.
func (*Label) HorizontalLine ¶
HorizontalLine adds a horizontal line at the specified position.
func (*Label) MarshalText ¶
MarshalText returns the ZPL code as a byte slice. Implements encoding.TextMarshaler.
func (*Label) PrintOrientationSetting ¶
func (l *Label) PrintOrientationSetting() PrintOrientation
PrintOrientationSetting returns the configured print orientation.
func (*Label) PrintQuantity ¶
PrintQuantity returns the print quantity (^PQ) - how many copies to print.
func (*Label) ReverseField ¶
ReverseField enables reverse printing for the next field.
func (*Label) SetBarcodeDefaults ¶
SetBarcodeDefaults sets the default barcode parameters.
func (*Label) SetCharacterSet ¶
SetCharacterSet sets the character encoding.
func (*Label) SetDefaultFont ¶
SetDefaultFont sets the default font for subsequent text fields.
func (*Label) SetHomeDots ¶
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 ¶
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) SetSizeDots ¶
SetSizeDots sets the label dimensions in dots.
func (*Label) 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) 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) VerticalLine ¶
VerticalLine adds a vertical line at the specified position.
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.
Source Files
¶
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. |
