Skip to main content

Printer

Class that controls the printer connection and printing functions.

constructor​

Initializes the printer object.

Example​

const printer = new Printer({
target: "BT:00:22:15:7D:70:9C",
deviceName: "TM-T88V",
})

Methods​

connect()​

connect(timeout?: string): Promise<void>

Starts communication with the printer.

Example

await printerInstance.connect();

Read more


disconnect()​

disconnect(): Promise<void>

Ends communication with the printer.

Example

await printerInstance.disconnect();

Read more


addText()​

addText(text: string): Promise<void>

Adds a character print command to the command buffer.

Example

await printerInstance.addText("Hello, World!");

Read more


addFeedLine()​

addFeedLine(line?: number): Promise<void>

Adds a paper-feed-by-line command to the command buffer.

Example

await printerInstance.addFeedLine(3);

Read more


addLineSpace()​

addLineSpace(linespc: number): Promise<void>

Adds line spacing setting to the command buffer.

Example

await printerInstance.addLineSpace(50);

Read more


sendData()​

sendData(timeout?: number): Promise<PrinterStatusResponse>

Sends the print command.

Example

const printerStatus = await printerInstance.sendData();

Read more


addCut()​

addCut(type?: AddCutTypeParam): Promise<void>

Adds a sheet cut command to the command buffer. Sets how to cut paper.

Example

await printerInstance.addCut(PrinterConstants.CUT_NO_FEED);

Read more


getPrinterSetting()​

getPrinterSetting(type: PrinterGetSettingsType, timeout?: number): Promise<PrinterSettingsResponse>

Acquires the set value of the printer setting. The value acquired by this API is notified to the listener method specified in the listener parameter.

Example

const printerSetting = await printerInstance.getPrinterSetting(PrinterConstants.PRINTER_SETTING_PAPERWIDTH);

Read more


getStatus()​

getStatus(): Promise<PrinterStatusResponse>

Acquires the current status information.

Example

const printerStatus = await printerInstance.getStatus();

Read more


addImage()​

addImage(params: AddImageParams): Promise<void>

Adds a raster image print command to the command buffer.

Example

await printerInstance.addImage({
source: require('../store.png'),
width: 100,
});

Read more


addBarcode()​

addBarcode(params: AddBarcodeParams): Promise<void>

Adds a barcode print command to the command buffer.

Example

await printerInstance.addBarcode({
data: 'Test123',
type: PrinterConstants.BARCODE_CODE93,
hri: PrinterConstants.HRI_BELOW,
width: 2,
height: 50,
});

Read more


addSymbol()​

addSymbol(params: AddSymbolParams): Promise<void>

Adds a 2D symbol print command to the command buffer.

Example

await printerInstance.addSymbol({
type: PrinterConstants.SYMBOL_QRCODE_MODEL_2,
level: PrinterConstants.LEVEL_M,
size: 5,
data: 'Test123',
});

Read more


addCommand()​

addCommand(data: Uint8Array): Promise<void>

Adds a command to the command buffer. Sends the ESC/POS command.

Example

import EscPosEncoder from 'esc-pos-encoder';

let encoder = new EscPosEncoder();

let result = encoder
.initialize()
.text('The quick brown fox jumps over the lazy dog')
.newline()
.qrcode('https://nielsleenheer.com')
.encode(); // or any other way to get the Uint8Array

await printerInstance.addCommand(result);

Read more


addPulse()​

addPulse(params?: AddPulseParams): Promise<void>

Adds a drawer kick command to the command buffer. Sets the drawer kick.

Example

await printerInstance.addPulse();

Read more


addTextAlign()​

addTextAlign(params?: AddTextAlignParam): Promise<void>

Adds a text alignment command to the command buffer.

Example

await printerInstance.addTextAlign(PrinterConstants.ALIGN_CENTER);

Read more


addTextSize()​

addTextSize(params?: AddTextSizeParams): Promise<void>

Adds character scaling factor setting to the command buffer.

Example

await printerInstance.addTextSize({
width: 2,
height: 2,
});

Read more


addTextSmooth()​

addTextSmooth(params?: AddTextSmoothParam): Promise<void>

Adds smoothing setting to the command buffer.

Example

await printerInstance.addTextSmooth(PrinterConstants.TRUE);

Read more


addTextStyle()​

addTextStyle(params?: AddTextStyleParams): Promise<void>

Adds character style setting to the command buffer.

Example

await printerInstance.addTextStyle({
em: PrinterConstants.TRUE,
ul: PrinterConstants.TRUE,
color: PrinterConstants.PARAM_UNSPECIFIED,
} as const);

Read more


addTextLang()​

addTextLang(lang: AddTextLangParam): Promise<void>

Adds language setting to the command buffer. A text string specified by the addText API is encoded according to the language specified by this API.

Example

await printerInstance.addTextLang(PrinterConstants.LANG_JA);

Read more


clearCommandBuffer()​

clearCommandBuffer(): Promise<void>

Clears the command buffer.

Example

await printerInstance.clearCommandBuffer();

Static Methods​

Printer.addTextLine()​

Printer.addTextLine(printerInstance: Printer, params: AddTextLineParams): Promise<void>

Prints text line with left and right parts.

Example

await Printer.addTextLine(printerInstance, {
left: 'Cheesburger',
right: '3 EUR',
gapSymbol: '_',
});

Read more


Printer.monitorPrinter()​

Printer.monitorPrinter(printerInstance: Printer, listener: Listener, interval: number): () => void

Starts monitoring the printer status.

Example

const stop = Printer.monitorPrinter(printerInstance, (status) => {
console.log(status);
});

// call stop() to stop monitoring

Read more


Printer.tryToConnectUntil()​

Printer.tryToConnectUntil(printerInstance: Printer, condition: (status: PrinterStatusResponse) => boolean): Promise<void>

Tries to connect to the printer until the condition is met.

Example

await Printer.tryToConnectUntil(
printerInstance,
(status) => status.online.statusCode === PrinterConstants.TRUE
);

Read more


Printer.addViewShot()​

Printer.addViewShot(printerInstance: Printer, params: AddViewShotParams): Promise<void>

Prints image captured from React Native View.

Requires react-native-view-shot to be installed.

yarn add react-native-view-shot

For iOS, run:

cd ios && pod install

Example

const ref = useRef<View>(null);

...

await Printer.addViewShot(printerInstance, {
viewNode: ref.current,
});

...

return (
<View ref={ref}>
<Text>Print me</Text>
</View>
);

Read more