Start a Project

USB Printer in React Native Android APP

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.

How to install it?

Installation-

Integrate Module-

To integrate react-native-usb-printer with the rest of your react app just execute:

How to use?

Import-Module-

Find Printer Devices & Connect one of them-

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.

  • “<M> … </M>”  – for Medium text.
  • <CM> … </CM> – center align and Medium text.
  • <C> …</C> – center alignment.
  • <B> …</B> for bold text.
  • many more tag.

Printing Text via Connected Printer-

By this library, we print our page by two types-

  • Print Without Cut Page- By this type, we print our many texts in a single Page.
  • Print With Cut Page – By this type, We print our text String on the page and then cut this page. Real life example- Printing Invoice for separate users

     

Printing Page Image-

Resources:-

https://www.npmjs.com/package/react-native-usb-printer

https://github.com/bondwp/react-native-usb-printer

 

 

Exit mobile version