seokju-na / react-thermal-printer

React for thermal printing
MIT License
269 stars 34 forks source link

Printing via Bluetooth #43

Closed Hassan-jr closed 1 year ago

Hassan-jr commented 1 year ago

Does this package support printing via Bluetooth and if yes please share an example.

Hassan-jr commented 1 year ago

@seokju-na Please respond to this.

seokju-na commented 1 year ago

Have you tried Web Bluetooth API? If the interface accepts Uint8Array, printing will available. Didn't test but you can try the code below. (or you can use bluetooth module works in Node.js)

import { Printer, Text } from 'react-thermal-printer';

const device = await navigator.bluetooth({ filters: [{ name: 'Printer' }] });
const server = await device.gatt.connect();
const service = await server.getPrimaryService('printer_service');
const characteristic = await service.getCharacteristic('printer_write_characteristic');

const data = await render(
  <Printer type="epson">
    <Text>Hello World</Text>
  </Printer>
);
await characteristic.writeValue(data.buffer);
Hassan-jr commented 1 year ago

@seokju-na Thanks for the response... Let me try that.

hempun10 commented 3 months ago

@Hassan-jr Hi, have you tried the web bluetooth api?