Class that controls the printer connection and printing functions.
Initializes the printer object.
const printer = new Printer({
target: "BT:00:22:15:7D:70:9C",
deviceName: "TM-T88V",
})
Starts communication with the printer.
await printerInstance.connect();
Ends communication with the printer.
await printerInstance.disconnect();
Adds a character print command to the command buffer.
await printerInstance.addText("Hello, World!");
Adds a paper-feed-by-line command to the command buffer.
await printerInstance.addFeedLine(3);
Adds line spacing setting to the command buffer.
await printerInstance.addLineSpace(50);
Sends the print command.
const printerStatus = await printerInstance.sendData();
Adds a sheet cut command to the command buffer. Sets how to cut paper.
await printerInstance.addCut(PrinterConstants.CUT_NO_FEED);
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.
const printerSetting = await printerInstance.getPrinterSetting(PrinterConstants.PRINTER_SETTING_PAPERWIDTH);
Acquires the current status information.
const printerStatus = await printerInstance.getStatus();
Adds a raster image print command to the command buffer.
await printerInstance.addImage({
source: require('../store.png'),
width: 100,
});
Adds a barcode print command to the command buffer.
await printerInstance.addBarcode({
data: 'Test123',
type: PrinterConstants.BARCODE_CODE93,
hri: PrinterConstants.HRI_BELOW,
width: 2,
height: 50,
});
Adds a 2D symbol print command to the command buffer.
await printerInstance.addSymbol({
type: PrinterConstants.SYMBOL_QRCODE_MODEL_2,
level: PrinterConstants.LEVEL_M,
size: 5,
data: 'Test123',
});
Adds a command to the command buffer. Sends the ESC/POS command.
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);
Adds a drawer kick command to the command buffer. Sets the drawer kick.
await printerInstance.addPulse();
Adds a text alignment command to the command buffer.
await printerInstance.addTextAlign(PrinterConstants.ALIGN_CENTER);
Adds character scaling factor setting to the command buffer.
await printerInstance.addTextSize({
width: 2,
height: 2,
});
Adds smoothing setting to the command buffer.
await printerInstance.addTextSmooth(PrinterConstants.TRUE);
Adds character style setting to the command buffer.
await printerInstance.addTextStyle({
em: PrinterConstants.TRUE,
ul: PrinterConstants.TRUE,
color: PrinterConstants.PARAM_UNSPECIFIED,
} as const);
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.
await printerInstance.addTextLang(PrinterConstants.LANG_JA);
Clears the command buffer.
await printerInstance.clearCommandBuffer();
Prints text line with left and right parts
await Printer.addTextLine(printerInstance, {
left: 'Cheesburger',
right: '3 EUR',
gapSymbol: '_',
});
Find more examples here
Starts monitoring the printer status.
const stop = Printer.monitorPrinter(printerInstance, (status) => {
console.log(status)
});
// call stop() to stop monitoring
Printer.tryToConnectUntil(printerInstance: Printer, condition: (status: PrinterStatusResponse) => boolean
): Promise<void>
Tries to connect to the printer until the condition is met.
await Printer.tryToConnectUntil(
printerInstance,
(status) => status.online.statusCode === PrinterConstants.TRUE
)
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
const ref = useRef<View>(null);
...
await Printer.addViewShot(printerInstance, {
viewNode: ref.current,
});
...
return (
<View ref={ref}>
<Text>Print me</Text>
</View>
);
Find detailed examples here