react-native-pos-printer v1.0.5
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
import RNPosPrinter from 'react-native-pos-printer';Init Printer
For the first time need to initialize the pos printer, the return will be Promise<void>
RNPosPrinter.init(true);Option
isDebug: boolean //default falseGet All Printer Devices
To get all printer devices you just need to call this one, the return will be Promise<Printer[]>
RNPosPrinter.getDevices()Scan Device
To scan all devices printer, the return will be Promise<boolean>
RNPosPrinter.scanDevices(callback);Option
callback: CallbackStop Scan Device
To stop scanning all devices printer, the return will be Promise<boolean>
RNPosPrinter.stopScanDevices();Connect Device
To connect to specific pos printer, the return will be Promise<any>
RNPosPrinter.connectDevice(deviceId, timeout);Option
deviceId: string
timeout: number //default 30000 msConnect And Print
To connect and automatically print on specific pos printer, the return will be Promise<any>
RNPosPrinter.connectAndPrintReceipt(deviceId);Option
deviceId: stringPrint Example
To print on pos printer
RNPosPrinter.printTestReceipt(storageUrl);Option
storageUrl: string //optional, if want to print imageMisc
If you want to use directly the printer command you can access on
RNPosPrinter.printerModule