react-native-thermal-receipt-printer
Fork of react-native-printer
and add implement for auto connect printer with usb
A React Native Library to support USB/BLE/Net printer
Installation
yarn add react-native-thermal-receipt-printer
Troubleshoot
- when install in
react-native
version >= 0.60, xcode show this error
duplicate symbols for architecture x86_64
that because the .a library uses CocoaAsyncSocket library and Flipper uses it too
Podfile
... use_native_modules! # Enables Flipper. # # Note that if you have use_frameworks! enabled, Flipper will not work and # you should disable these next few lines. # add_flipper_pods! # post_install do |installer| # flipper_post_install(installer) # end...
and comment out code related to Flipper in ios/AppDelegate.m
Support
Printer | Android | IOS |
---|---|---|
USBPrinter | ✔️ | |
BLEPrinter | ✔️ | ✔️ |
NetPrinter | ✔️ | ✔️ |
Predefined tag
Tags | Description |
---|---|
C | Center |
D | Medium font |
B | Large font |
M | Medium font |
CM | Medium font, centered |
CB | Medium font, centered |
CD | Large font, centered |
Development workflow
To get started with the project, run yarn bootstrap
in the root directory to install the required dependencies for each package:
yarn bootstrap
While developing, you can run the example app to test your changes.
To start the packager:
yarn example start
To run the example app on Android:
yarn example dev-android
To run the example app on iOS:
yarn example ios
Usage
; USBPrinter;USBPrinter;
Example
USBPrinter (only support android)
const printers setPrinters = ; const currentPrinter setCurrentPrinter = ; { ifPlatformOS == 'android' USBPrinter } const _connectPrinter = USBPrinter const printTextTest = { currentPrinter && USBPrinter; } const printBillTest = { currentPrinter && USBPrinter; } ... return <View style=stylescontainer> printers <TouchableOpacity onPress=printTextTest> <Text>Print Text</Text> </TouchableOpacity> <TouchableOpacity onPress=printBillTest> <Text>Print Bill Text</Text> </TouchableOpacity> </View> ...
BLEPrinter
const printers setPrinters = ; const currentPrinter setCurrentPrinter = ; ; { //connect printer BLEPrinter } { currentPrinter && USBPrinter; } { currentPrinter && USBPrinter; } ... return <View style=stylescontainer> thisstateprinters <TouchableOpacity onPress=printTextTest> <Text>Print Text</Text> </TouchableOpacity> <TouchableOpacity onPress=printBillTest> <Text>Print Bill Text</Text> </TouchableOpacity> </View> ...
NetPrinter
Note: get list device for net printers is support scanning in local ip but not recommended
{ NetPrinter } { //connect printer NetPrinter} { if thisstatecurrentPrinter NetPrinter; } { ifthisstatecurrentPrinter NetPrinter; } ... { return <View style=stylescontainer> thisstateprinters <TouchableOpacity onPress= this> <Text> Print Text </Text> </TouchableOpacity> <TouchableOpacity onPress= this> <Text> Print Bill Text </Text> </TouchableOpacity> </View> } ...