label API reference
Describe and print labels for industrial label printers. One module, one way to describe a label, with the printer language as a selectable backend (a Device dialect), not a module per printer. A three-stage pipeline keeps the stages independent: build a device-independent Label in millimetres, render it to a chosen dialect string, then emit that string anywhere (a file, a database, or the thin send convenience over net to a printer's :9100 raw port). Dialects: "zpl" (Zebra Programming Language, raster - needs the target dpi) and "cab" (cab JScript, millimetre-native); each dialect encoder lives in its own file (label_zpl.inc.j / label_cab.inc.j) spliced in via include, so a new dialect is a new file plus a branch in render. Build and render are pure and run on both binaries; only send needs the default jennifer binary.
Import with import "label.j" as label;. See the label guide for prose and examples.
Contents
| Name | What it is |
|---|---|
barcode | Place a barcode field, returning a new Label. |
box | Place a rectangular box (outline), returning a new Label. |
cab | Build a cab JScript render target with default print-setup. |
cabWith | Build a cab JScript render target carrying explicit cab print-setup. |
image | Place an image referenced by name, returning a new Label. |
new | Start a new, empty label of the given size in millimetres (quantity 1). |
quantity | Set the number of copies to print, returning a new Label. |
render | Render a label to a dialect command string. |
send | Send a rendered command stream to a printer's raw :9100 port over TCP. |
text | Place a text field, returning a new Label. |
zpl | Build a ZPL render target for a printer of the given resolution. |
BarcodeOptions | struct: Optional refinements for a barcode. |
CabSetup | struct: cab-only print-setup that has no ZPL equivalent, carried on the render target so it can be reproduced witho... |
Device | struct: The render target: which dialect to emit and, for raster dialects, the printer resolution. |
Field | struct: One field on a label. |
Label | struct: A device-independent label: its physical size in millimetres, the number of copies to print, and its fields. |
TextOptions | struct: Options for a text field. |
Functions
barcode
label.barcode(
label as Label,
type as string,
x as float,
y as float,
opts as BarcodeOptions,
data as string)Place a barcode field, returning a new Label. type is a linear symbology - "code128", "ean13", "ean8", "itf" (Interleaved 2 of 5), "code39", "gs1-128" - or a 2D symbology - "datamatrix", "qr". opts refines it (size, check digit, 2D error level, human-readable line); pass a zero-value BarcodeOptions for the defaults. ITF is numeric-only and even-length (its digits are paired): non-numeric data is rejected and odd-length data is padded with a leading zero (so a 13-digit body becomes ITF-14). GS1-128 data uses the parenthesised Application Identifier form, e.g. (00)3006....
label- the label to extend
type- the barcode symbology ("code128"/"ean13"/"ean8"/"itf"/"code39"/"gs1-128"/"datamatrix"/"qr")
x- the x origin in millimetres
y- the y origin in millimetres
opts- size / check-digit / error-level / text refinements
data- the barcode data
- Returns
Label - a new Label with the barcode field added
- Throws
Error - kind "label" for an unknown type, a negative origin, invalid data (empty; EAN / ITF not numeric; EAN of the wrong length or check digit; Code 39 outside its character set) or invalid options (a negative size, an unknown check digit, an error level other than L / M / Q / H or on a linear code)
box
label.box(
label as Label,
x as float,
y as float,
w as float,
h as float,
thickness as float)Place a rectangular box (outline), returning a new Label.
label- the label to extend
x- the x origin in millimetres
y- the y origin in millimetres
w- the box width in millimetres
h- the box height in millimetres
thickness- the line thickness in millimetres
- Returns
Label - a new Label with the box added
- Throws
Error - kind "label" for a negative origin or a size that is not positive
cab
label.cab()Build a cab JScript render target with default print-setup.
- Returns
Device - a cab device
cabWith
label.cabWith(setup as CabSetup)Build a cab JScript render target carrying explicit cab print-setup.
setup- the cab-only print-setup (job name, heat, orientation, sensor, geometry)
- Returns
Device - a cab device
image
label.image(label as Label, x as float, y as float, name as string)Place an image referenced by name, returning a new Label. The image must be pre-stored on the printer (cab: the images/ folder; ZPL: a stored graphic); name is the stored name in that dialect's convention. Printed at native size. (Embedding a bitmap in the job is a planned follow-on.)
label- the label to extend
x- the x origin in millimetres
y- the y origin in millimetres
name- the stored image name
- Returns
Label - a new Label with the image field added
- Throws
Error - kind "label" for a negative origin or an empty name
new
label.new(width as float, height as float)Start a new, empty label of the given size in millimetres (quantity 1).
width- the label width in millimetres
height- the label height in millimetres
- Returns
Label - a fresh, empty label
- Throws
Error - kind "label" when width or height is not positive
quantity
label.quantity(label as Label, n as int)Set the number of copies to print, returning a new Label.
label- the label to update
n- the number of copies, 1..99,999,999
- Returns
Label - a new Label with the quantity set
- Throws
Error - kind "label" for a count outside 1..99,999,999
render
label.render(label as Label, device as Device)Render a label to a dialect command string.
label- the label to render
device- the target dialect (and dpi for raster dialects)
- Returns
string - the printer command stream
- Throws
Error - kind "label" for an unknown dialect, or a quantity outside 1..99,999,999 (set directly on the struct)
send
label.send(host as string, port as int, rendered as string)Send a rendered command stream to a printer's raw :9100 port over TCP.
host- the printer host or IP
port- the raw print port (usually 9100)
rendered- the rendered command stream from
render - Throws
Error - on a network failure (a positioned
neterror)
text
label.text(
label as Label,
x as float,
y as float,
opts as TextOptions,
content as string)Place a text field, returning a new Label.
label- the label to extend
x- the x origin in millimetres
y- the y origin in millimetres
opts- the text options (font height)
content- the text to print
- Returns
Label - a new Label with the text field added
- Throws
Error - kind "label" for a negative origin, a rotation other than 0 / 90 / 180 / 270, a negative size, or neither
pointsnorheightset
zpl
label.zpl(dpi as int)Build a ZPL render target for a printer of the given resolution.
dpi- the printer dots-per-inch
- Returns
Device - a ZPL device
Structs
BarcodeOptions
Optional refinements for a barcode. A zero-value struct (def o as label.BarcodeOptions;) means no options: default size, no added check digit, default error correction, human-readable line shown.
def struct BarcodeOptions {
height as float,
checkDigit as string,
errorLevel as string,
hideText as bool,
moduleWidth as float,
ratio as float
};height- bar height (linear) or module size (2D) in millimetres; 0 uses the default
checkDigit- append an auto-computed check digit: "" (none), "mod10", "mod11", "mod16", "mod36", or "mod43"
errorLevel- 2D error-correction level: "" (default), "L", "M", "Q", or "H"
hideText- true suppresses a linear barcode's human-readable line
moduleWidth- a linear barcode's narrow-element width in millimetres; 0 uses the dialect default (cab; zpl uses its own default module width)
ratio- the wide:narrow bar ratio for a ratio-based code (Interleaved 2 of 5 / Code 39); 0 uses the default (3)
CabSetup
cab-only print-setup that has no ZPL equivalent, carried on the render target so it can be reproduced without leaking into the device-independent Label. A zero-value struct emits none of it (a bare J, no H/O line, and an S line derived from the label size). Every field is optional; the cab encoder emits a command only when the corresponding field is set. ZPL ignores it all.
def struct CabSetup {
jobName as string,
heat as int,
speed as int,
mode as string,
orientation as string,
sensor as string,
xOffset as float,
yOffset as float,
height as float,
pitch as float,
width as float,
columnPitch as float,
columns as int
};jobName- the
Jjob name; "" emits a bareJ heat- the
Hheat/contrast level speed- the
Hprint speed mode- the trailing
Htokens verbatim, e.g. "T,R0"; "" and heat/speed 0 omit theHline orientation- the
Oorientation token, e.g. "R"; "" omits theOline sensor- the
Sphotocell/sensor type, e.g. "l1" (die-cut labels with gap); "" emits no prefix xOffset- the
Shorizontal origin offset in millimetres yOffset- the
Svertical origin offset in millimetres height- the
Slabel height in millimetres (transport direction); 0 derives the wholeSline from the label size pitch- the
Slabel pitch in millimetres (label height + gap between labels) width- the
Slabel width in millimetres columnPitch- the
Shorizontal distance to the next column in millimetres (multi-up dies) columns- the
Snumber of labels across; <= 1 emits a single-up geometry
Device
The render target: which dialect to emit and, for raster dialects, the printer resolution. Build one with label.zpl(dpi), label.cab(), or label.cabWith(setup) rather than a raw literal.
def struct Device {
dialect as string,
dpi as int,
cab as CabSetup
};dialect- "zpl" or "cab"
dpi- the printer dots-per-inch (used by "zpl"; ignored by "cab")
cab- cab-only print-setup (ignored by "zpl")
Field
One field on a label. kind selects which attributes matter: "text" uses h as the font height and data as the content; "barcode" uses barcodeType, h (bar height, or module size for a 2D code), and data; "box" uses w, h, thickness; "image" uses data as the stored name.
def struct Field {
kind as string,
x as float,
y as float,
w as float,
h as float,
thickness as float,
barcodeType as string,
data as string,
checkDigit as string,
errorLevel as string,
hideText as bool,
rotation as int,
points as int,
bold as bool,
moduleWidth as float,
ratio as float
};kind- "text", "barcode", "box", or "image"
x- the x origin in millimetres
y- the y origin in millimetres
w- the box width in millimetres (0 otherwise)
h- box height / barcode height (or 2D module size) / text font height, in millimetres
thickness- the box line thickness in millimetres (0 otherwise)
barcodeType- the symbology for a barcode field (empty otherwise)
data- the text content, barcode data, or image name
checkDigit- a barcode's auto-computed check digit ("" | "mod10" | ...)
errorLevel- a 2D barcode's error-correction level ("" | "L" | "M" | "Q" | "H")
hideText- suppress a linear barcode's human-readable line
rotation- text rotation in degrees counter-clockwise (0, 90, 180, 270)
points- text font size in points; 0 means use
has a millimetre height bold- bold text face
moduleWidth- a linear barcode's narrow-element width in millimetres (0 = dialect default)
ratio- a ratio-based barcode's wide:narrow ratio (0 = dialect default)
Label
A device-independent label: its physical size in millimetres, the number of copies to print, and its fields. Value-semantic - every builder returns a new Label.
def struct Label {
width as float,
height as float,
quantity as int,
fields as list of Field
};width- the label width in millimetres
height- the label height in millimetres
quantity- the number of copies to print
fields- the placed fields
TextOptions
Options for a text field. A zero-value struct (def o as label.TextOptions;) means an unrotated, non-bold field sized by height. Set points for a point-sized font (it wins over height).
def struct TextOptions {
height as float,
points as int,
rotation as int,
bold as bool
};height- the font height in millimetres (used when
pointsis 0) points- the font size in points; when > 0 it is used instead of
height rotation- rotation in degrees counter-clockwise: 0, 90, 180, or 270
bold- true selects a bold face (cab: Swiss 721 Bold; ZPL ignores it, its
^A0font being bold already)