Skip to content

Latest commit

 

History

History
353 lines (230 loc) · 7.11 KB

File metadata and controls

353 lines (230 loc) · 7.11 KB

Printer

Class that controls the printer connection and printing functions.

Initializes the printer object.

Example

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

Methods

Starts communication with the printer.

Example

await printerInstance.connect();

Ends communication with the printer.

Example

await printerInstance.disconnect();

Adds a character print command to the command buffer.

Example

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

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

Example

await printerInstance.addFeedLine(3);

Adds line spacing setting to the command buffer.

Example

await printerInstance.addLineSpace(50);

Sends the print command.

Example

const printerStatus = await printerInstance.sendData();

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

Example

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.

Example

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

Acquires the current status information.

Example

const printerStatus = await printerInstance.getStatus();

Adds a raster image print command to the command buffer.

Example

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

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

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',
});

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);

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

Example

await printerInstance.addPulse();

Adds a text alignment command to the command buffer.

Example

await printerInstance.addTextAlign(PrinterConstants.ALIGN_CENTER);

Adds character scaling factor setting to the command buffer.

Example

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

Adds smoothing setting to the command buffer.

Example

await printerInstance.addTextSmooth(PrinterConstants.TRUE);

Adds character style setting to the command buffer.

Example

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.

Example

await printerInstance.addTextLang(PrinterConstants.LANG_JA);

clearCommandBuffer(): Promise<void>

Clears the command buffer.

Example

await printerInstance.clearCommandBuffer();

Static Methods

Prints text line with left and right parts

Example

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

Find more examples here

Starts monitoring the printer status.

Example

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

 // call stop() to stop monitoring

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

Example

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

Example

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