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.
Functions
label.barcode(label as Label, x as float, y as float, type as string, 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....
Parameters
label{Label}- the label to extendx{float}- the x origin in millimetresy{float}- the y origin in millimetrestype{string}- the barcode symbology ("code128"/"ean13"/"ean8"/"itf"/"code39"/"gs1-128"/"datamatrix"/"qr")opts{BarcodeOptions}- size / check-digit / error-level / text refinementsdata{string}- the barcode data
Returns {Label} - a new Label with the barcode field added
Throws
{Error}- kind "label" for an unknown type or invalid ITF data
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.
Parameters
label{Label}- the label to extendx{float}- the x origin in millimetresy{float}- the y origin in millimetresw{float}- the box width in millimetresh{float}- the box height in millimetresthickness{float}- the line thickness in millimetres
Returns {Label} - a new Label with the box added
label.cab()
Build a cab JScript render target with default print-setup.
Returns {Device} - a cab device
label.cabWith(setup as CabSetup)
Build a cab JScript render target carrying explicit cab print-setup.
Parameters
setup{CabSetup}- the cab-only print-setup (job name, heat, orientation, sensor, geometry)
Returns {Device} - a cab device
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.)
Parameters
label{Label}- the label to extendx{float}- the x origin in millimetresy{float}- the y origin in millimetresname{string}- the stored image name
Returns {Label} - a new Label with the image field added
label.new(width as float, height as float)
Start a new, empty label of the given size in millimetres (quantity 1).
Parameters
width{float}- the label width in millimetresheight{float}- the label height in millimetres
Returns {Label} - a fresh, empty label
label.quantity(label as Label, n as int)
Set the number of copies to print, returning a new Label.
Parameters
label{Label}- the label to updaten{int}- the number of copies
Returns {Label} - a new Label with the quantity set
label.render(label as Label, device as Device)
Render a label to a dialect command string.
Parameters
label{Label}- the label to renderdevice{Device}- the target dialect (and dpi for raster dialects)
Returns {string} - the printer command stream
Throws
{Error}- kind "label" for an unknown dialect
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.
Parameters
host{string}- the printer host or IPport{int}- the raw print port (usually 9100)rendered{string}- the rendered command stream fromrender
Throws
{Error}- on a network failure (a positionedneterror)
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.
Parameters
label{Label}- the label to extendx{float}- the x origin in millimetresy{float}- the y origin in millimetresopts{TextOptions}- the text options (font height)content{string}- the text to print
Returns {Label} - a new Label with the text field added
label.zpl(dpi as int)
Build a ZPL render target for a printer of the given resolution.
Parameters
dpi{int}- the printer dots-per-inch
Returns {Device} - a ZPL device
Structs
label.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.
| Field | Type | Description |
|---|---|---|
height | float | bar height (linear) or module size (2D) in millimetres; 0 uses the default |
checkDigit | string | append an auto-computed check digit: "" (none), "mod10", "mod11", "mod16", "mod36", or "mod43" |
errorLevel | string | 2D error-correction level: "" (default), "L", "M", "Q", or "H" |
hideText | bool | true suppresses a linear barcode's human-readable line |
moduleWidth | float | a linear barcode's narrow-element width in millimetres; 0 uses the dialect default (cab; zpl uses its own default module width) |
ratio | float | the wide:narrow bar ratio for a ratio-based code (Interleaved 2 of 5 / Code 39); 0 uses the default (3) |
label.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.
| Field | Type | Description |
|---|---|---|
jobName | string | the J job name; "" emits a bare J |
heat | int | the H heat/contrast level |
speed | int | the H print speed |
mode | string | the trailing H tokens verbatim, e.g. "T,R0"; "" and heat/speed 0 omit the H line |
orientation | string | the O orientation token, e.g. "R"; "" omits the O line |
sensor | string | the S photocell/sensor type, e.g. "l1" (die-cut labels with gap); "" emits no prefix |
xOffset | float | the S horizontal origin offset in millimetres |
yOffset | float | the S vertical origin offset in millimetres |
height | float | the S label height in millimetres (transport direction); 0 derives the whole S line from the label size |
pitch | float | the S label pitch in millimetres (label height + gap between labels) |
width | float | the S label width in millimetres |
columnPitch | float | the S horizontal distance to the next column in millimetres (multi-up dies) |
columns | int | the S number of labels across; <= 1 emits a single-up geometry |
label.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.
| Field | Type | Description |
|---|---|---|
dialect | string | "zpl" or "cab" |
dpi | int | the printer dots-per-inch (used by "zpl"; ignored by "cab") |
cab | CabSetup | cab-only print-setup (ignored by "zpl") |
label.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.
| Field | Type | Description |
|---|---|---|
kind | string | "text", "barcode", "box", or "image" |
x | float | the x origin in millimetres |
y | float | the y origin in millimetres |
w | float | the box width in millimetres (0 otherwise) |
h | float | box height / barcode height (or 2D module size) / text font height, in millimetres |
thickness | float | the box line thickness in millimetres (0 otherwise) |
barcodeType | string | the symbology for a barcode field (empty otherwise) |
data | string | the text content, barcode data, or image name |
checkDigit | string | a barcode's auto-computed check digit ("" | "mod10" | ...) |
errorLevel | string | a 2D barcode's error-correction level ("" | "L" | "M" | "Q" | "H") |
hideText | bool | suppress a linear barcode's human-readable line |
rotation | int | text rotation in degrees counter-clockwise (0, 90, 180, 270) |
points | int | text font size in points; 0 means use h as a millimetre height |
bold | bool | bold text face |
moduleWidth | float | a linear barcode's narrow-element width in millimetres (0 = dialect default) |
ratio | float | a ratio-based barcode's wide:narrow ratio (0 = dialect default) |
label.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.
| Field | Type | Description |
|---|---|---|
width | float | the label width in millimetres |
height | float | the label height in millimetres |
quantity | int | the number of copies to print |
fields | list of Field | the placed fields |
label.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).
| Field | Type | Description |
|---|---|---|
height | float | the font height in millimetres (used when points is 0) |
points | int | the font size in points; when > 0 it is used instead of height |
rotation | int | rotation in degrees counter-clockwise: 0, 90, 180, or 270 |
bold | bool | true selects a bold face |