Create a new USB printer instance.
USB configuration options
Configuration options for the Usb printer.
Optionalinterface?: numberUSB interface number to claim (default: 0). Most ESC/POS printers expose a single printer interface at index 0.
USB Product ID (e.g. 0x0202 for Epson TM-T88IV)
OptionalprofileName?: stringPrinter profile name to use (default: 'default')
USB Vendor ID (e.g. 0x04b8 for Epson)
Write raw bytes to the USB bulk-OUT endpoint.
This is the low-level method called by all higher-level Escpos methods. The transfer is fire-and-forget (callback-based), matching how most POS printers operate — they accept data as fast as the host can send it.
Buffer containing ESC/POS command bytes to send
Print a hardware barcode.
Sends the appropriate GS k sequence for the requested barcode type and
function type. Supports all types defined in BARCODE_TYPES
(UPC-A, UPC-E, EAN8, EAN13, CODE39, ITF, NW7/CODABAR, CODE93, CODE128,
and GS1 variants for Function Type B).
Barcode data string.
Barcode type name (e.g. 'CODE128', 'EAN13').
Names are normalised (non-alphanumeric removed, uppercased) before lookup.
Optional barcode appearance settings; see BarcodeOptions.
BarcodeTypeError if the type is unrecognised or unsupported.
BarcodeCodeError if code fails format validation and
opts.check is true (default).
BarcodeSizeError if height or width are out of range.
Print a word-wrapped text block.
Wraps txt at word boundaries to fit within the column width of the
selected font, as reported by the active printer profile.
UTF-8 string to wrap and print.
Font to use for column-width lookup ('a' or 'b'; default: 'a').
Optionalcolumns: numberOverride column count (uses profile value if omitted).
Send a cash-drawer open pulse.
Cash-drawer pin: 2, 5, or a 5-element array
[esc, p, m, t1, t2] for a custom DEC sequence.
CashDrawerError if pin is not 2, 5, or a valid 5-element array.
Cut the paper.
Feeds 6 lines before cutting unless feed is false. Falls back to a
full cut when the profile does not support partial cuts, and vice versa.
'FULL' (default) for a complete cut, 'PART' to leave
a small uncut section.
Feed paper before cutting (default: true).
Send a hardware control command to the printer.
| Action | Command | Effect |
|---|---|---|
'INIT' |
ESC @ |
Clear print buffer and reset modes to defaults |
'SELECT' |
ESC = |
Select printer as the active peripheral |
'RESET' |
ESC ? |
Soft reset |
One of 'INIT', 'SELECT', or 'RESET'.
Print an image from a file path or raw image Buffer.
Supported formats: PNG, JPEG, BMP, GIF, TIFF.
The image is:
fragmentHeight.impl and written via _raw().impl options:
'bitImageRaster' (default) — GS v 0; widest printer compatibility.'graphics' — GS ( L; better alignment on some models.'bitImageColumn' — ESC *; required for printers like IT80-002.Absolute file path or raw image Buffer.
Image rendering options; see ImageOptions.
ImageWidthError if the image is wider than the profile's declared media width.
Open the line display, clear it, write text, then close it.
Convenience wrapper around linedisplaySelect, linedisplayClear, and Escpos.text.
Text to display on the customer-facing line display.
Set or reset the line spacing.
When called without arguments, resets line spacing to the printer default
(ESC 2). When spacing is provided, sets the line spacing to
spacing / divisor inches per dot using the matching ESC/POS command:
| Divisor | Command | Range |
|---|---|---|
| 60 | ESC A |
0–85 |
| 180 | ESC 3 |
0–255 |
| 360 | ESC + |
0–255 |
Optionalspacing: numberSpacing value in dots (omit to reset).
Unit divisor: 60, 180, or 360 (default: 180).
Open the USB device, claim the interface, and locate endpoints.
Resolves when the device is ready to receive data. Rejects with USBNotFoundError if:
Promise that resolves when the device is open and claimed
Print a QR code.
Two rendering modes are available, controlled by opts.native:
Software mode (native: false, default) — generates the QR matrix
locally using the qrcode package and sends it as a raster image via
image. Works on all printers that support raster images.
Native mode (native: true) — sends the five GS ( k sub-commands
(set model, size, error correction, store data, print) directly.
Requires the printer to have a built-in QR engine (most Epson TM series).
Read data from the USB bulk-IN endpoint (if present).
Used to retrieve printer status bytes (e.g. paper-out, cover-open). If no IN endpoint was found during open, rejects immediately.
Number of bytes to request (default: 64)
Promise resolving with a Buffer containing received data
Apply ESC/POS text style attributes.
Each field in opts that is defined emits the corresponding ESC/POS
command immediately. Omitted fields are not changed on the printer.
For size changes, exactly one of customSize, doubleWidth,
doubleHeight, or normalTextSize should be set.
Style attributes to apply; see TextStyleOptions.
SetVariableError if customSize is set but width or
height is outside the 1–8 range.
Apply text styles with full defaults merged in.
Merges opts over a complete default set (left align, Font A, no
bold, no underline, 1×1 size, density 9) before calling set.
Also auto-enables customSize when width or height > 1 is requested
without an explicit size mode, so callers do not need to set the flag manually.
Calling with no arguments resets the printer to standard text defaults.
Partial style overrides (default: {} — full reset).
Print a row of text in software-defined columns.
Lays out textList into adjacent fixed-width columns, word-wrapping each
cell and aligning content per the corresponding align entry. Outputs
one textln() call per row of the resulting grid.
Print a string using automatic encoding selection.
Characters are encoded via MagicEncode, which automatically
selects the best code page for each segment of the string and emits
the necessary ESC t n code-page-switch commands.
UTF-8 string to print.
StaticcheckValidate a barcode code string against the format rules for a given barcode type.
Checks that the code length falls within an allowed range and that the string matches the required character set for the barcode type.
Barcode type name (e.g. 'CODE128', 'EAN13').
Barcode data string to validate.
true if the code is valid for the given type.
StaticlistReturn a flat list of every USB device currently visible to libusb, without any class-based filtering.
Useful for quickly enumerating all connected devices when you want to let the caller decide which one is a printer (e.g. GUI device pickers). For printer-only results with string descriptor resolution, use listPrinters instead.
Array of UsbDeviceInfo objects (synchronous)
StaticlistScan for connected USB printers.
Strategy: exclude devices whose class is definitively NOT a printer (HID, hub, audio, video, mass storage, etc.). For everything else, try to confirm via interface class 7. If the OS has claimed the device (common on Windows with usbprint.sys) and we cannot inspect interface descriptors, we include the device anyway — a claimed device on Windows is almost always a printer or printer-adjacent peripheral.
After class detection, attempts to read the manufacturer and product name string descriptors by briefly opening the device. This fails gracefully when the device is driver-owned.
Promise resolving to an array of printer UsbDeviceInfo objects
USB printer implementation.
Communicates with an ESC/POS printer over USB using the
usbnpm package (libusb bindings). Finds the device by Vendor/Product ID, claims the first matching interface, and writes to the first bulk-OUT endpoint.Example
Since
1.0.0