API

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): Label
const label = new Label({ width: inches(4), height: inches(6), dpmm: 8 });
PropertyTypeDefaultDescription
widthLength

Label width (^PW)

heightLength

Label height (^LL)

dpmm6 | 8 | 12 | 24

Dots per millimeter of the printer: 6, 8, 12 or 24 for 152, 203, 300 or 600 dpi

reverse?booleanfalse

Print the label white on black (^LR)

characterSet?number28 (UTF-8)

Character set (^CI)

home?PositionThe top left corner

Where positions are measured from (^LH)

minify?booleantrue

Leave out line breaks between commands in the output

copies?number1

How many copies to print (^PQ)

speed?numberThe printer's setting

Print speed in inches per second, 1 to 14 depending on the printer (^PR)

darkness?number0

Darkness relative to the printer's setting, -30 to 30 (^MD)

Methods

MethodZPLAdds
text^A, ^FDText
box^GBA box or line
ellipse^GEAn ellipse
circle^GCA circle
graphic^GFAn image
storedGraphic^XGAn image stored on the printer
fieldanyA field with any command
Barcodes^B…One method per barcode
setDefaultFont^CFThe default font
setFieldOrientation^FWThe default orientation
toZPLThe finished ZPL
lintProblems the printer won't report

Drawing

text

label.text(options: TextOptions): this

Adds 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) },
});
PropertyTypeDefaultDescription
positionPosition

Where the field starts

textstring

The text; characters ZPL would read as commands are escaped

font?FontOptionsThe 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?LengthNone

Extra space between characters (^FP)

clock?booleanfalse

Fill in date and time codes like %Y-%m-%d %H:%M from the printer's clock (^FC)

block?TextBlockOptionsOne line

Wrap the text in a block (^FB)

serial?SerialOptionsThe same text on every copy

Count the text up on each copy, from the number at its end (^SN)

font takes:

PropertyTypeDefaultDescription
name?stringFont 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:

PropertyTypeDefaultDescription
widthLength

Width of the block; lines wrap at spaces to fit it

lines?number1

Most lines; more print over the last one

lineSpacing?LengthNone

Extra space between lines

align?"center" | "justify" | "left" | "right""left"

How lines line up in the block

indent?LengthNone

How far lines after the first are indented

serial takes the following. Barcodes, except QR codes, take it too, to count their data up.

PropertyTypeDefaultDescription
increment?number1

How much the last run of digits counts up by; negative counts down

leadingZeros?booleantrue

Keep leading zeros, like 001; without, they print as spaces

box

label.box(options: BoxOptions): this

Adds 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),
});
PropertyTypeDefaultDescription
positionPosition

Where the box starts

widthLength

Box width

heightLength

Box height

thicknessLength

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 | 80

How round the corners are, from 0 (square) to 8

ellipse

label.ellipse(options: EllipseOptions): this

Adds 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),
});
PropertyTypeDefaultDescription
positionPosition

Where the ellipse's box starts

widthLength

Ellipse width

heightLength

Ellipse height

thicknessLength

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): this

Adds a circle.

PropertyTypeDefaultDescription
positionPosition

Where the circle's box starts

diameterLength

Circle diameter

thicknessLength

Line thickness; half the diameter draws a solid circle

color?Color"B"

B for black, W for white

graphic

label.graphic(options: GraphicOptions): this

Adds an image converted with ImageConverter.

PropertyTypeDescription
positionPosition

Where the graphic starts

graphicGraphic

The image, for example from ImageConverter

storedGraphic

label.storedGraphic(options: StoredGraphicOptions): this

Prints an image stored on the printer with PrinterSetup.storeGraphic, without sending it again.

PropertyTypeDefaultDescription
positionPosition

Where the graphic starts

namestring

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): this

Adds 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",
});
PropertyTypeDescription
positionPosition

Where the field starts

commandunion

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.

PropertyTypeDefaultDescription
positionPosition

Where the barcode starts

datastring

The data to encode; it's escaped for you

orientation?Orientation

Which way the barcode runs

serial?SerialOptionsThe same data on every copy

Count the data up on each copy, from the number at its end (^SN)

height?LengthThe height set with ^BY

Bar height

printHri?booleantrue

Print the data as text with the bars

printHriAbove?booleanfalse

Print that text above the bars instead of below

code128

label.code128(options: Code128Options): this

Code 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:

PropertyTypeDefaultDescription
useUcc?booleanfalse

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): this

Code 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:

PropertyTypeDefaultDescription
checkDigit?booleanfalse

Add a Mod-43 check digit

code93

label.code93(options: Code93Options): this

Code 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:

PropertyTypeDefaultDescription
printCheckDigit?booleanfalse

Print the two check characters in the interpretation line

code11

label.code11(options: Code11Options): this

Code 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:

PropertyTypeDefaultDescription
checkDigits?1 | 22

Number of check digits

codabar

label.codabar(options: CodabarOptions): this

ANSI 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:

PropertyTypeDefaultDescription
start?"A" | "B" | "C" | "D""A"

The start character

stop?"A" | "B" | "C" | "D""A"

The stop character

ean13

label.ean13(options: Ean13Options): this

EAN-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): this

EAN-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): this

UPC-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:

PropertyTypeDefaultDescription
printCheckDigit?booleantrue

Print the check digit in the interpretation line

upcE

label.upcE(options: UpcEOptions): this

UPC-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:

PropertyTypeDefaultDescription
printCheckDigit?booleantrue

Print the check digit in the interpretation line

upcEanExtension

label.upcEanExtension(options: UpcEanExtensionOptions): this

The 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): this

Interleaved 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:

PropertyTypeDefaultDescription
checkDigit?booleanfalse

Add a Mod-10 check digit

industrial2of5

label.industrial2of5(options: Industrial2of5Options): this

Industrial 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): this

Standard 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): this

LOGMARS, 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): this

MSI: 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:

PropertyTypeDefaultDescription
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?booleanfalse

Print the check digits in the interpretation line

plessey

label.plessey(options: PlesseyOptions): this

Plessey: 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:

PropertyTypeDefaultDescription
printCheckDigit?booleanfalse

Print the two check characters in the interpretation line

postnet

label.postnet(options: PostnetOptions): this

USPS 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): this

USPS 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): this

USPS 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): this

GS1 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:

PropertyTypeDefaultDescription
type?union"omnidirectional"

Which GS1 DataBar

moduleSize?Length2 dots, 3 at 300 dpi and 6 at 600 dpi

Size of a module, 1 to 10 dots

separatorHeight?1 | 21

Height of the separator rows in stacked symbols, in modules

segments?number22

Segments per row for Expanded, an even number from 2 to 22

pdf417

label.pdf417(options: Pdf417Options): this

PDF417, 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:

PropertyTypeDefaultDescription
rowHeight?LengthThe height set with ^BY

Height of each row

securityLevel?0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 80

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?booleanfalse

Leave out the right row indicators and stop pattern

microPdf417

label.microPdf417(options: MicroPdf417Options): this

MicroPDF417, 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:

PropertyTypeDefaultDescription
rowHeight?LengthThe height set with ^BY

Height of each row

mode?number0

0 to 33, which sets the columns, rows and error correction; the reference lists them

qrCode

label.qrCode(options: QrCodeOptions): this

QR 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:

PropertyTypeDefaultDescription
moduleSize?LengthThe 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): this

Data 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:

PropertyTypeDefaultDescription
moduleSizeLength

Size of each square module

quality?0 | 50 | 80 | 100 | 140 | 200200 (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): this

Aztec 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:

PropertyTypeDefaultDescription
moduleSize?LengthThe 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): this

MaxiCode, 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:

PropertyTypeDefaultDescription
mode?2 | 3 | 4 | 5 | 62

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): this

Sets the font (^CF) for text that doesn't set one.

PropertyTypeDescription
fontstring

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): this

Sets the orientation (^FW) of the fields that follow and don't give one.

Output

MethodReturns
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
commandsThe label's command nodes

Lower level

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