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

 

 

. . .

Comments (7)

Add Your Comment

  • Ivan Yusuf
    What React native is used? react-native-cli or expo-cli. I am using expo-cli and getting a problem with the RNPrinter.getUSBDeviceList (), where the object does not defined
  • Ivan Yusuf
    What printer do you use in the test?
    • ashwini gupta
      It supports any USB Printers. I have used & test on EPSON POS Printer. Also, deliver App to my client and there is no issue on his printer.
  • Rickard
    Hi, i tried this tutorial, but run into some problems. Please view about those problems here : https://stackoverflow.com/questions/56928890/react-native-usb-printer-library-not-working

    Thank you.

    • ashwini gupta
      Hello, you need to add tools:replace = “android:allowbackup” on tag with manifest file. AndroidManifest file is found in android -> app of your folder structure.
      look your issue screenshot http://i.prntscr.com/jMd2qcffTd2OHj3RjUV6aA.png

      For More detail for merging Android Manifest click here

      • Rickard
        Hi, thank you for replying, i wonder have you ever tested this tutorial for the recent version of react native? We are currently at version 0.60.0. Which react-native version you use to test this library?
  • css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close