Updated 6 March 2021
In this blog, I am describing to implement USB Printer in react native Application. it is the toughest task to implement printer in our Application. I have learned many libraries and found a library “react-native-usb-printer” that supports for Android Platform. It is very easy to use. It detects all connected USB Printer to our device if we got All Printer select one of them as a default Printer.
Installation-
1 |
npm install react-native-usb-printer --save |
Integrate Module-
To integrate react-native-usb-printer
 with the rest of your react app just execute:
1 |
react-native link react-native-usb-printer |
Import-Module-
1 |
import { RNUSBPrinter } from 'react-native-usb-printer'; |
Find Printer Devices & Connect one of them-
1 2 3 4 5 6 7 8 9 |
let devices = await RNUSBPrinter.getUSBDeviceList(); console.log("Devices", devices); if (devices && devices.length > 0) { let printedSelected = await RNUSBPrinter.connectPrinter( devices[0].vendor_id, devices[0].product_id ); } |
Generate Text for printing-
We have to Note that it print only text String that encodes in “encoding: ‘GBK’ ” System. It Provides it’s own format to print our text. There are following some formatted TAG that supports by this library.
Printing Text via Connected Printer-
By this library, we print our page by two types-
1 |
RNUSBPrinter.printText('Hello') |
1 |
RNUSBPrinter.printBillTextWithCut("<C>Hello</C>") |
Printing Page Image-
Resources:-
https://www.npmjs.com/package/react-native-usb-printer
https://github.com/bondwp/react-native-usb-printer
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
vendor_id: 8578,
device_id: 2007,
device_name: ‘/dev/bus/usb/002/007’ },
{ product_id: 278,
vendor_id: 1561,
device_id: 2006,
device_name: ‘/dev/bus/usb/002/006’ } ]
I am getting this whether devices are attached or not?