Skip to content
Jennifer Programming Language

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

NameWhat it is
barcodePlace a barcode field, returning a new Label.
boxPlace a rectangular box (outline), returning a new Label.
cabBuild a cab JScript render target with default print-setup.
cabWithBuild a cab JScript render target carrying explicit cab print-setup.
imagePlace an image referenced by name, returning a new Label.
newStart a new, empty label of the given size in millimetres (quantity 1).
quantitySet the number of copies to print, returning a new Label.
renderRender a label to a dialect command string.
sendSend a rendered command stream to a printer's raw :9100 port over TCP.
textPlace a text field, returning a new Label.
zplBuild a ZPL render target for a printer of the given resolution.
BarcodeOptionsstruct: Optional refinements for a barcode.
CabSetupstruct: cab-only print-setup that has no ZPL equivalent, carried on the render target so it can be reproduced witho...
Devicestruct: The render target: which dialect to emit and, for raster dialects, the printer resolution.
Fieldstruct: One field on a label.
Labelstruct: A device-independent label: its physical size in millimetres, the number of copies to print, and its fields.
TextOptionsstruct: Options for a text field.

Functions

barcode

jennifer
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

jennifer
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

jennifer
label.cab()

Build a cab JScript render target with default print-setup.

Returns Device
a cab device

cabWith

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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

jennifer
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 net error)

text

jennifer
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 points nor height set

zpl

jennifer
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.

jennifer
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.

jennifer
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 J job name; "" emits a bare J
heat
the H heat/contrast level
speed
the H print speed
mode
the trailing H tokens verbatim, e.g. "T,R0"; "" and heat/speed 0 omit the H line
orientation
the O orientation token, e.g. "R"; "" omits the O line
sensor
the S photocell/sensor type, e.g. "l1" (die-cut labels with gap); "" emits no prefix
xOffset
the S horizontal origin offset in millimetres
yOffset
the S vertical origin offset in millimetres
height
the S label height in millimetres (transport direction); 0 derives the whole S line from the label size
pitch
the S label pitch in millimetres (label height + gap between labels)
width
the S label width in millimetres
columnPitch
the S horizontal distance to the next column in millimetres (multi-up dies)
columns
the S number 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.

jennifer
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.

jennifer
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 h as 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.

jennifer
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).

jennifer
def struct TextOptions {
    height as float,
    points as int,
    rotation as int,
    bold as bool
};
height
the font height in millimetres (used when points is 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 ^A0 font being bold already)