Label
The Label builder from @zplkit/core, its methods and their options.
import { Label, inches, mm, dots, Orientation, ZebraFontFamily } from "@zplkit/core";Label builds one label as a list of ZPL commands. Each drawing method adds a field and returns the label, so calls chain. Method calls introduces it; this page lists every method and option.
new Label(options)
new Label(options: LabelOptions): Labelconst label = new Label({ width: inches(4), height: inches(6), dpmm: 8 });| Property | Type | Default | Description |
|---|---|---|---|
width | Length | Label width (^PW) | |
height | Length | Label height (^LL) | |
dpmm | 6 | 8 | 12 | 24 | Dots per millimeter of the printer: 6, 8, 12 or 24 for 152, 203, 300 or 600 dpi | |
reverse? | boolean | false | Print the label white on black (^LR) |
characterSet? | number | 28 (UTF-8) | Character set (^CI) |
home? | Position | The top left corner | Where positions are measured from (^LH) |
minify? | boolean | true | Leave out line breaks between commands in the output |
copies? | number | 1 | How many copies to print (^PQ) |
speed? | number | The printer's setting | Print speed in inches per second, 1 to 14 depending on the printer (^PR) |
darkness? | number | 0 | Darkness relative to the printer's setting, -30 to 30 (^MD) |
Methods
| Method | ZPL | Adds |
|---|---|---|
text | ^A, ^FD | Text |
box | ^GB | A box or line |
ellipse | ^GE | An ellipse |
circle | ^GC | A circle |
graphic | ^GF | An image |
storedGraphic | ^XG | An image stored on the printer |
field | any | A field with any command |
| Barcodes | ^B… | One method per barcode |
setDefaultFont | ^CF | The default font |
setFieldOrientation | ^FW | The default orientation |
toZPL | The finished ZPL | |
lint | Problems the printer won't report |
Drawing
text
label.text(options: TextOptions): thisAdds text in one of the printer's fonts or a font file on the printer. Characters ZPL would read as commands are escaped.
label.text({
position: { x: mm(5), y: mm(5) },
text: "Harbor Parts Co.",
font: { height: mm(5) },
});| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the field starts | |
text | string | The text; characters ZPL would read as commands are escaped | |
font? | FontOptions | The label's default font | The font to use |
direction? | "horizontal" | "reverse" | "vertical" | "horizontal" | Which way the characters run: across, down (one under the other) or right to left (^FP) |
letterSpacing? | Length | None | Extra space between characters (^FP) |
clock? | boolean | false | Fill in date and time codes like %Y-%m-%d %H:%M from the printer's clock (^FC) |
block? | TextBlockOptions | One line | Wrap the text in a block (^FB) |
serial? | SerialOptions | The same text on every copy | Count the text up on each copy, from the number at its end (^SN) |
font takes:
| Property | Type | Default | Description |
|---|---|---|---|
name? | string | Font 0 | One of the printer's fonts, or a font name |
file? | string | A font file on the printer instead, like "E:ARIAL.TTF" | |
height? | Length | Character height | |
width? | Length | Character width | |
orientation? | Orientation | Which way the text runs |
Text can run down or right to left, be spaced out, wrap in a block, show the printer's date and time, or count up on each copy:
// 001, 002, 003… on the 500 copies
const label = new Label({ width: inches(4), height: inches(2), dpmm: 8, copies: 500 });
label.text({ position: { x: mm(5), y: mm(5) }, text: "001", serial: {} });
// Printed 28.10.2026, from the printer's clock
label.text({ position: { x: mm(5), y: mm(15) }, text: "Printed %d.%m.%Y", clock: true });
// Wrapped in a block 60 mm wide, centered, on up to 3 lines
label.text({
position: { x: mm(5), y: mm(25) },
text: "Keep dry and away from direct sunlight",
block: { width: mm(60), lines: 3, align: "center" },
});block takes:
| Property | Type | Default | Description |
|---|---|---|---|
width | Length | Width of the block; lines wrap at spaces to fit it | |
lines? | number | 1 | Most lines; more print over the last one |
lineSpacing? | Length | None | Extra space between lines |
align? | "center" | "justify" | "left" | "right" | "left" | How lines line up in the block |
indent? | Length | None | How far lines after the first are indented |
serial takes the following. Barcodes, except QR codes, take it too, to count their data up.
| Property | Type | Default | Description |
|---|---|---|---|
increment? | number | 1 | How much the last run of digits counts up by; negative counts down |
leadingZeros? | boolean | true | Keep leading zeros, like 001; without, they print as spaces |
box
label.box(options: BoxOptions): thisAdds a box, or a line when one side is as thin as the border.
// A 0.5 mm rule across the label
label.box({
position: { x: mm(5), y: mm(30) },
width: mm(91),
height: mm(0.5),
thickness: mm(0.5),
});| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the box starts | |
width | Length | Box width | |
height | Length | Box height | |
thickness | Length | Line thickness; the smaller of width and height draws a solid box | |
color? | Color | "B" | B for black, W for white |
rounding? | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 0 | How round the corners are, from 0 (square) to 8 |
ellipse
label.ellipse(options: EllipseOptions): thisAdds an ellipse, or a solid one when the line is half its width or height.
label.ellipse({
position: { x: mm(5), y: mm(5) },
width: mm(30),
height: mm(15),
thickness: mm(0.5),
});| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the ellipse's box starts | |
width | Length | Ellipse width | |
height | Length | Ellipse height | |
thickness | Length | Line thickness; half the width or height draws a solid ellipse | |
color? | Color | "B" | B for black, W for white |
circle
label.circle(options: CircleOptions): thisAdds a circle.
| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the circle's box starts | |
diameter | Length | Circle diameter | |
thickness | Length | Line thickness; half the diameter draws a solid circle | |
color? | Color | "B" | B for black, W for white |
graphic
label.graphic(options: GraphicOptions): thisAdds an image converted with ImageConverter.
| Property | Type | Description |
|---|---|---|
position | Position | Where the graphic starts |
graphic | Graphic | The image, for example from ImageConverter |
storedGraphic
label.storedGraphic(options: StoredGraphicOptions): thisPrints an image stored on the printer with PrinterSetup.storeGraphic, without sending it again.
| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the graphic starts | |
name | string | Name of the graphic on the printer | |
device? | StorageDevice | "R" | Where the graphic is stored: R (DRAM), E (flash), B or A |
magnification? | object | \{ x: 1, y: 1 \} | How many times larger to print it, across and down |
field
label.field(options: FieldOptions): thisAdds a field with any command, for elements without their own method. The command is added as written, and the data is escaped.
label.field({
position: { x: mm(5), y: mm(5) },
command: "^B8N,100,Y,N",
data: "1234567",
});| Property | Type | Description |
|---|---|---|
position | Position | Where the field starts |
command | union | The command(s) for the field, added as written, like "^B3N,N,100,Y,N" |
data? | string | Field data, if the command needs any; it's escaped for you |
Barcodes
The linear barcodes take these options. The 2D codes take position, data and orientation, plus the options listed with them.
| Property | Type | Default | Description |
|---|---|---|---|
position | Position | Where the barcode starts | |
data | string | The data to encode; it's escaped for you | |
orientation? | Orientation | Which way the barcode runs | |
serial? | SerialOptions | The same data on every copy | Count the data up on each copy, from the number at its end (^SN) |
height? | Length | The height set with ^BY | Bar height |
printHri? | boolean | true | Print the data as text with the bars |
printHriAbove? | boolean | false | Print that text above the bars instead of below |
code128
label.code128(options: Code128Options): thisCode 128, the general-purpose barcode for letters, digits and punctuation. Shipping and logistics labels use it most. Writes ^BC.
label.code128({
position: { x: mm(5), y: mm(5) },
data: "ORD-10442",
height: mm(12),
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
useUcc? | boolean | false | Add a UCC check digit |
mode? | "A" | "D" | "N" | "U" | "N" | N (none), U (UCC case), A (automatic) or D (UCC/EAN) |
code39
label.code39(options: Code39Options): thisCode 39: capital letters, digits, space and - . $ / + %. Wider than Code 128 for the same data. Writes ^B3.
label.code39({
position: { x: mm(5), y: mm(5) },
data: "PART-77",
checkDigit: true,
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
checkDigit? | boolean | false | Add a Mod-43 check digit |
code93
label.code93(options: Code93Options): thisCode 93, a denser Code 39 with two check characters, which the printer always adds. Writes ^BA.
label.code93({
position: { x: mm(5), y: mm(5) },
data: "PART-77",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
printCheckDigit? | boolean | false | Print the two check characters in the interpretation line |
code11
label.code11(options: Code11Options): thisCode 11: digits and dashes, used on telecom equipment. Writes ^B1.
label.code11({
position: { x: mm(5), y: mm(5) },
data: "123-45",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
checkDigits? | 1 | 2 | 2 | Number of check digits |
codabar
label.codabar(options: CodabarOptions): thisANSI Codabar: digits and - $ : / . + between a start and a stop letter, A to D. Writes ^BK.
label.codabar({
position: { x: mm(5), y: mm(5) },
data: "31117013206375",
start: "B",
stop: "D",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
start? | "A" | "B" | "C" | "D" | "A" | The start character |
stop? | "A" | "B" | "C" | "D" | "A" | The stop character |
ean13
label.ean13(options: Ean13Options): thisEAN-13 for retail products. Pass 12 digits; the printer adds the check digit. Writes ^BE.
label.ean13({
position: { x: mm(5), y: mm(5) },
data: "590123412345",
});It takes only the options above.
ean8
label.ean8(options: Ean8Options): thisEAN-8 for small retail packages. Pass 7 digits; the printer adds the check digit. Writes ^B8.
label.ean8({
position: { x: mm(5), y: mm(5) },
data: "9638507",
});It takes only the options above.
upcA
label.upcA(options: UpcAOptions): thisUPC-A, the 12 digit retail code used in North America. Pass 11 digits; the printer adds the check digit. Writes ^BU.
label.upcA({
position: { x: mm(5), y: mm(5) },
data: "03600029145",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
printCheckDigit? | boolean | true | Print the check digit in the interpretation line |
upcE
label.upcE(options: UpcEOptions): thisUPC-E, a UPC-A number compressed to 6 digits for small packages. Pass the UPC-A number without its check digit: 10 digits, or 11 starting with the number system. Writes ^B9.
label.upcE({
position: { x: mm(5), y: mm(5) },
data: "1230000045",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
printCheckDigit? | boolean | true | Print the check digit in the interpretation line |
upcEanExtension
label.upcEanExtension(options: UpcEanExtensionOptions): thisThe 2 or 5 digit add-on printed to the right of a UPC or EAN code, for example a magazine's issue number. Give it its own position, a little lower and shorter than the main code. Its digits print above the bars by default. Writes ^BS.
label.upcEanExtension({
position: { x: mm(5), y: mm(5) },
data: "04414",
});It takes only the options above.
interleaved2of5
label.interleaved2of5(options: Interleaved2of5Options): thisInterleaved 2 of 5: digits in pairs, common on cartons. The printer adds a leading zero to an odd number of digits. Writes ^B2.
label.interleaved2of5({
position: { x: mm(5), y: mm(5) },
data: "10012345678902",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
checkDigit? | boolean | false | Add a Mod-10 check digit |
industrial2of5
label.industrial2of5(options: Industrial2of5Options): thisIndustrial 2 of 5: digits, for systems that still read it. Writes ^BI.
label.industrial2of5({
position: { x: mm(5), y: mm(5) },
data: "123456",
});It takes only the options above.
standard2of5
label.standard2of5(options: Standard2of5Options): thisStandard 2 of 5: digits, for systems that still read it. Writes ^BJ.
label.standard2of5({
position: { x: mm(5), y: mm(5) },
data: "123456",
});It takes only the options above.
logmars
label.logmars(options: LogmarsOptions): thisLOGMARS, Code 39 with a check digit, for U.S. Department of Defense labels. It always prints its text. Writes ^BL.
label.logmars({
position: { x: mm(5), y: mm(5) },
data: "12AB",
});It takes the options above, except printHri.
msi
label.msi(options: MsiOptions): thisMSI: digits, used on shelf labels. One Mod 10 check digit by default. Writes ^BM.
label.msi({
position: { x: mm(5), y: mm(5) },
data: "123456",
checkDigits: "C",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
checkDigits? | "A" | "B" | "C" | "D" | "B" | A for none, B for one Mod 10, C for two Mod 10, D for Mod 11 then Mod 10 |
printCheckDigit? | boolean | false | Print the check digits in the interpretation line |
plessey
label.plessey(options: PlesseyOptions): thisPlessey: digits and A to F, used on shelf labels. The printer adds an 8 bit check. Writes ^BP.
label.plessey({
position: { x: mm(5), y: mm(5) },
data: "12345",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
printCheckDigit? | boolean | false | Print the two check characters in the interpretation line |
postnet
label.postnet(options: PostnetOptions): thisUSPS POSTNET: a ZIP code of 5, 9 or 11 digits as tall and short bars. The printer adds the check digit, and doesn't print the digits unless printHri is set. Writes ^BZ.
label.postnet({
position: { x: mm(5), y: mm(5) },
data: "12345",
height: dots(40),
});It takes the linear barcode options above, with printHri off by default.
planet
label.planet(options: PlanetOptions): thisUSPS PLANET: 11 or 13 digits as tall and short bars. Writes ^B5.
label.planet({
position: { x: mm(5), y: mm(5) },
data: "12345678901",
height: dots(40),
});It takes the linear barcode options above, with printHri off by default.
intelligentMail
label.intelligentMail(options: IntelligentMailOptions): thisUSPS Intelligent Mail: a 20 digit tracking code followed by a routing code of 0, 5, 9 or 11 digits. Writes ^BZ.
label.intelligentMail({
position: { x: mm(5), y: mm(5) },
data: "00123123456123456789",
height: dots(40),
});It takes position, data, orientation and height, and never prints its digits.
gs1DataBar
label.gs1DataBar(options: Gs1DataBarOptions): thisGS1 DataBar. The first five types take a GTIN of up to 13 digits; Expanded takes GS1 element strings without parentheses, like 010001234567890517251231. Composite symbols, with a 2D part after a |, aren't drawn by the renderer yet. Writes ^BR.
label.gs1DataBar({
position: { x: mm(5), y: mm(5) },
data: "12345678901",
type: "stacked",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
type? | union | "omnidirectional" | Which GS1 DataBar |
moduleSize? | Length | 2 dots, 3 at 300 dpi and 6 at 600 dpi | Size of a module, 1 to 10 dots |
separatorHeight? | 1 | 2 | 1 | Height of the separator rows in stacked symbols, in modules |
segments? | number | 22 | Segments per row for Expanded, an even number from 2 to 22 |
pdf417
label.pdf417(options: Pdf417Options): thisPDF417, a stacked 2D code for a few hundred characters, used on shipping labels and IDs. Writes ^B7.
label.pdf417({
position: { x: mm(5), y: mm(5) },
data: "SHIP 10442 TO AMARA OKAFOR",
columns: 4,
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
rowHeight? | Length | The height set with ^BY | Height of each row |
securityLevel? | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 0 | Error correction level, from 0 (detection only) to 8 |
columns? | number | Number of data columns, 1 to 30 | |
rows? | number | Number of rows, 3 to 90 | |
truncate? | boolean | false | Leave out the right row indicators and stop pattern |
microPdf417
label.microPdf417(options: MicroPdf417Options): thisMicroPDF417, a smaller PDF417 for little data. The mode picks its columns, rows and error correction; the ^BF page lists them. Writes ^BF.
label.microPdf417({
position: { x: mm(5), y: mm(5) },
data: "ABC123",
mode: 3,
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
rowHeight? | Length | The height set with ^BY | Height of each row |
mode? | number | 0 | 0 to 33, which sets the columns, rows and error correction; the reference lists them |
qrCode
label.qrCode(options: QrCodeOptions): thisQR code. The error correction level is added to the data as ZPL requires. Writes ^BQ.
label.qrCode({
position: { x: mm(5), y: mm(5) },
data: "https://example.com/orders/10442",
moduleSize: dots(5),
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
moduleSize? | Length | The printer's default for its resolution | Size of each square module |
errorCorrection? | "H" | "L" | "M" | "Q" | "M" | H (highest), Q, M (standard) or L (densest) |
dataMatrix
label.dataMatrix(options: DataMatrixOptions): thisData Matrix, the small square code used to mark parts and medicine. moduleSize is required. Writes ^BX.
label.dataMatrix({
position: { x: mm(5), y: mm(5) },
data: "SN-10442",
moduleSize: dots(4),
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
moduleSize | Length | Size of each square module | |
quality? | 0 | 50 | 80 | 100 | 140 | 200 | 200 (ECC 200) | Error correction level |
columns? | number | Number of columns | |
rows? | number | Number of rows | |
formatId? | 1 | 2 | 3 | 4 | 5 | 6 | Format ID, not used with quality 200 | |
escapeCharacter? | string | Escape sequence control character |
aztec
label.aztec(options: AztecOptions): thisAztec code, a square code with a bullseye in the middle, used on tickets. Writes ^BO.
label.aztec({
position: { x: mm(5), y: mm(5) },
data: "TICKET 10442",
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
moduleSize? | Length | The printer's default for its resolution | Size of each square module, 1 to 10 dots |
errorControl? | number | Error correction percentage (1 to 99), or 101 to 104 for a compact symbol and 201 to 232 for a full-range one with that many layers |
maxiCode
label.maxiCode(options: MaxiCodeOptions): thisMaxiCode, the fixed-size code on UPS parcels. In modes 2 and 3 the data starts with the class of service, country code and postal code. Writes ^BD.
label.maxiCode({
position: { x: mm(5), y: mm(5) },
data: "001840100014000012345",
mode: 2,
});Besides the common options:
| Property | Type | Default | Description |
|---|---|---|---|
mode? | 2 | 3 | 4 | 5 | 6 | 2 | 2 or 3 for carrier messages with a numeric or alphanumeric postal code, 4 to 6 for other data. In modes 2 and 3 the data starts with the class of service, country code and postal code. |
Settings
setDefaultFont
label.setDefaultFont(options: DefaultFontOptions): thisSets the font (^CF) for text that doesn't set one.
| Property | Type | Description |
|---|---|---|
font | string | One of the printer's fonts, like ZebraFontFamily.ZERO, or a font name |
height? | Length | Character height |
width? | Length | Character width |
setFieldOrientation
label.setFieldOrientation(orientation: Orientation): thisSets the orientation (^FW) of the fields that follow and don't give one.
Output
| Method | Returns |
|---|---|
toZPL() | The ZPL, closed with ^XZ if it isn't already |
lint() | Problems the printer won't report, as LintDiagnostics |
validate(strict?) | Nothing; throws a ZplError for unclosed fields, and with strict (the default) for unknown commands |
commands | The label's command nodes |
Lower level
| Method | Adds |
|---|---|
add(...commands) | Typed command nodes, as written. Nothing is escaped. |
raw(zpl) | Plain ZPL, as written. Nothing is escaped, so keep user input out. |
open(), close() | ^XA and ^XZ, for several formats in one label |
Types
Length, Position, Orientation and the other shared types are described in Types.