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
Thank you.
look your issue screenshot http://i.prntscr.com/jMd2qcffTd2OHj3RjUV6aA.png
For More detail for merging Android Manifest click here
Thanks for posting this in the above description you have mention “supports for Android Platform” so this library wouldn’t work for IOS devices / IOS platform?