react-native-pos-printer
react native module for printing receipt on pos printer.
For now it's only support for android
Prerequisites
You must install the following library to your react native project
- RNFetchBlob (optional) if you want to print with image
Getting started
$ npm install react-native-pos-printer --save
Mostly automatic installation
$ react-native link react-native-pos-printer
Manual installation
iOS
Still not supported yet
Android
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.reactlibrary.RNPosPrinterPackage;
to the imports at the top of the file - Add
new RNPosPrinterPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-pos-printer' project(':react-native-pos-printer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-pos-printer/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-pos-printer')
Usage
;
Init Printer
For the first time need to initialize the pos printer, the return will be Promise<void>
RNPosPrinter;
Option
isDebug: boolean //default false
Get All Printer Devices
To get all printer devices you just need to call this one, the return will be Promise<Printer[]>
RNPosPrinter
Scan Device
To scan all devices printer, the return will be Promise<boolean>
RNPosPrinter;
Option
callback: Callback
Stop Scan Device
To stop scanning all devices printer, the return will be Promise<boolean>
RNPosPrinter;
Connect Device
To connect to specific pos printer, the return will be Promise<any>
RNPosPrinter;
Option
deviceId: stringtimeout: number //default 30000 ms
Connect And Print
To connect and automatically print on specific pos printer, the return will be Promise<any>
RNPosPrinter;
Option
deviceId: string
Print Example
To print on pos printer
RNPosPrinter;
Option
storageUrl: string //optional, if want to print image
Misc
If you want to use directly the printer command you can access on
RNPosPrinterprinterModule