@cacio/react-native-bluetooth-escpos-printer
v1.0.2
Published
React-Native plugin for the bluetooth ESC/POS printers.
Downloads
22
Maintainers
Readme
@cacio/react-native-bluetooth-escpos-printer
Fork ajustado de januslo/react-native-bluetooth-escpos-printer Compatível com Gradle atualizado e Android 13+.
Biblioteca React Native para integração com impressoras Bluetooth ESC/POS & TSC. Ideal para recibos, etiquetas e integração com dispositivos Android.
✨ Features
- Suporte a ESC/POS (recibos) e TSC (etiquetas)
- Gerenciamento de Bluetooth (parear, conectar, listar dispositivos)
- Compatível com TypeScript
- Testado principalmente em Android
- Em desenvolvimento ativo
📦 Instalação
1. Instalar pacote
npm install @cacio/react-native-bluetooth-escpos-printer
# ou
yarn add @cacio/react-native-bluetooth-escpos-printer2. Link (apenas RN < 0.60)
react-native link @cacio/react-native-bluetooth-escpos-printerPara React Native 0.60+, o autolinking cuida disso automaticamente ✅.
3. Importar no projeto
import {
BluetoothManager,
BluetoothEscposPrinter,
BluetoothTscPrinter
} from '@cacio/react-native-bluetooth-escpos-printer';🚀 Uso rápido
Verificar se Bluetooth está ativo
const enabled = await BluetoothManager.checkBluetoothEnabled();
console.log(enabled); // true | falseAtivar e listar dispositivos pareados
const devices = await BluetoothManager.enableBluetooth();Escanear novos dispositivos
const { found, paired } = JSON.parse(await BluetoothManager.scanDevices());Conectar a um dispositivo
await BluetoothManager.connect("XX:XX:XX:XX:XX:XX");Imprimir texto simples
await BluetoothEscposPrinter.printText("Olá, mundo!\n\r", {
encoding: 'GBK',
widthtimes: 1,
heigthtimes: 1,
fonttype: 0,
});Imprimir etiqueta TSC
await BluetoothTscPrinter.printLabel({
width: 40,
height: 30,
text: [
{
text: "Etiqueta Teste",
x: 20,
y: 20,
fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,
rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,
xscal: BluetoothTscPrinter.FONTMUL.MUL_1,
yscal: BluetoothTscPrinter.FONTMUL.MUL_1,
}
],
});📚 APIs disponíveis
- BluetoothManager → gerenciamento de Bluetooth
- BluetoothTscPrinter → impressão de etiquetas
- BluetoothEscposPrinter → impressão de recibos ESC/POS
🔧 BluetoothManager
Funções principais:
checkBluetoothEnabled()→ verifica se Bluetooth está ativoenableBluetooth()→ ativa e retorna dispositivos pareadosscanDevices()→ procura novos dispositivosconnect(address)→ conecta a um dispositivodisconnect(address)→ desconectagetConnectedDeviceAddress()→ retorna o endereço atualunpair(address)→ desfaz pareamento
Eventos emitidos:
EVENT_DEVICE_ALREADY_PAIRED, EVENT_DEVICE_FOUND, EVENT_CONNECTED, EVENT_CONNECTION_LOST, etc.
🖨️ BluetoothTscPrinter
Usado para etiquetas. Principais métodos:
printLabel(options)→ imprime etiqueta (texto, QRCode, imagem, etc.)
🧾 BluetoothEscposPrinter
Usado para recibos ESC/POS. Principais métodos:
printerInit()printText(text, options)printColumn(cols, aligns, texts, options)printQRCode(content, size, correctionLevel)printBarCode(...)printPic(base64, options)cutOnePoint()openDrawer(pin, onTime, offTime)
🐞 Contribuição
Achou um bug ou precisa de uma melhoria? Abra uma issue ou envie um PR 🚀
📜 Licença
MIT © cacio
