Package Exports
- @mateusdegobi/react-native-bluetooth-escpos-printer
- @mateusdegobi/react-native-bluetooth-escpos-printer/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@mateusdegobi/react-native-bluetooth-escpos-printer) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React Native Bluetooth ESC/POS & TSC Printer
React Native plugin for Bluetooth ESC/POS & TSC printers.
π‘ Still under development.
β Currently supports Android, iOS support planned.
Any questions or bugs? Please open an issue.
π§© Acknowledgments
This project is a continuation of the excellent work started by Janus J K Lu and later improved by Ccdilan. This fork by Farid Fatkhurrozak (Vardrz) builds upon Ccdilanβs version β adding TypeScript support, minor native fixes, and extra print options.
Special thanks to both Janus and Ccdilan β their contributions laid the foundation
for this version to exist and continue evolving.
π¦ Installation
Install via NPM:
npm install @vardrz/react-native-bluetooth-escpos-printer --saveOr install via GitHub:
npm install https://github.com/vardrz/react-native-bluetooth-escpos-printer.git --saveπ Usage
Import module
import {
BluetoothManager,
BluetoothEscposPrinter,
BluetoothTscPrinter
} from '@vardrz/react-native-bluetooth-escpos-printer';π§ BluetoothManager
Manages Bluetooth service: status check, enable/disable, scan, connect/unpair.
β isBluetoothEnabled
Check whether Bluetooth is enabled.
BluetoothManager.isBluetoothEnabled().then(enabled => {
alert(enabled); // true / false
}, err => alert(err));β enableBluetooth (Android only)
Enable Bluetooth service and return paired devices.
BluetoothManager.enableBluetooth().then(r => {
const paired = r.map(item => JSON.parse(item));
console.log('Paired devices:', paired);
});β disableBluetooth (Android only)
Disable Bluetooth service.
BluetoothManager.disableBluetooth().then(() => {
console.log('Bluetooth disabled');
});β scanDevices
Scans nearby devices and returns paired/found results.
BluetoothManager.scanDevices().then(s => {
const result = JSON.parse(s);
console.log(result.paired, result.found);
});β connect / unpair
BluetoothManager.connect(device.address)
.then(() => console.log('Connected!'))
.catch(e => alert(e));
BluetoothManager.unpair(device.address)
.then(() => console.log('Unpaired'))
.catch(e => alert(e));π‘ Events
| Event Key | Description |
|---|---|
EVENT_DEVICE_ALREADY_PAIRED |
Emits paired devices array |
EVENT_DEVICE_DISCOVER_DONE |
Emits when scanning completes |
EVENT_DEVICE_FOUND |
Emits when new device found |
EVENT_CONNECTION_LOST |
Emits when connection lost |
EVENT_UNABLE_CONNECT |
Emits when connection fails |
EVENT_CONNECTED |
Emits when connected |
EVENT_BLUETOOTH_NOT_SUPPORT |
Device does not support BT (Android only) |
π¨οΈ BluetoothTscPrinter (Label Printer)
Used for label printing.
β printLabel(options)
BluetoothTscPrinter.printLabel(options)
.then(() => console.log('Label printed'))
.catch(err => console.error(err));Example Options
const options = {
width: 40,
height: 30,
gap: 20,
direction: BluetoothTscPrinter.DIRECTION.FORWARD,
reference: [0, 0],
tear: BluetoothTscPrinter.TEAR.ON,
sound: 0,
text: [
{
text: 'Sample Text',
x: 20, y: 0,
fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,
rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,
xscal: BluetoothTscPrinter.FONTMUL.MUL_1,
yscal: BluetoothTscPrinter.FONTMUL.MUL_1
}
],
qrcode: [
{ x: 20, y: 96, level: BluetoothTscPrinter.EEC.LEVEL_L, width: 3, code: 'show me the money' }
],
barcode: [
{ x: 120, y: 96, type: BluetoothTscPrinter.BARCODETYPE.CODE128, height: 40, readable: 1, code: '1234567890' }
],
image: [
{ x: 160, y: 160, mode: BluetoothTscPrinter.BITMAP_MODE.OVERWRITE, width: 60, image: base64Image }
]
};π§Ύ BluetoothEscposPrinter (Receipt Printer)
Follows ESC/POS command set for text & image printing.
β printerInit
Initialize printer.
β printText(text, options)
Prints text with options:
BluetoothEscposPrinter.printText("Hello World\n", {
encoding: 'GBK',
widthtimes: 1,
heigthtimes: 1,
fonttype: 0,
cut: true
});β printPic(base64, options)
Prints image (base64 encoded).
Options:
| Key | Type | Description |
|---|---|---|
width |
int | Target width (dots) |
left |
int | Left padding (ignored if center true) |
center |
bool | Center horizontally |
autoCut |
bool | Auto-cut after print (default true) |
paperSize |
int | Paper width (58 / 80 mm) |
Example:
BluetoothEscposPrinter.printPic(base64Image, {
width: 384,
center: true,
paperSize: 80,
autoCut: false
});β printColumn
Print columns (table-style layout).
await BluetoothEscposPrinter.printColumn(
[12, 6, 6, 8],
[BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.CENTER, BluetoothEscposPrinter.ALIGN.CENTER, BluetoothEscposPrinter.ALIGN.RIGHT],
['Item', 'Qty', 'Price', 'Total'],
{}
);π§Ύ Full Example: Print a Receipt
await BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);
await BluetoothEscposPrinter.printText("My Store\n\r", { widthtimes: 3, heigthtimes: 3 });
await BluetoothEscposPrinter.printText("Sales Receipt\n\r", {});
await BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT);
await BluetoothEscposPrinter.printText("Customer: Retail\n\r", {});
await BluetoothEscposPrinter.printText("Invoice: INV20251014\n\r", {});
await BluetoothEscposPrinter.printText("--------------------------------\n\r", {});
let columnWidths = [12, 6, 6, 8];
await BluetoothEscposPrinter.printColumn(columnWidths,
[0, 1, 1, 2],
['Product', 'Qty', 'Price', 'Total'],
{}
);
await BluetoothEscposPrinter.printText("--------------------------------\n\r", {});
await BluetoothEscposPrinter.printText("Total: $64.00\n\r", {});
await BluetoothEscposPrinter.printText("Thank you!\n\r\n\r", {});π‘ Open Drawer
BluetoothEscposPrinter.openDrawer(0, 250, 250);