Skip to content

taro-bluetooth-print高性能蓝牙打印库

热敏票据 · 标签打印 · 多平台适配 · 离线缓存 · 断点续传

npm 安装

bash
pnpm add taro-bluetooth-print

快速使用

typescript
import { BluetoothPrinter, DeviceManager } from 'taro-bluetooth-print';

async function main() {
  // 1. 扫描发现打印机
  const deviceManager = new DeviceManager();
  deviceManager.on('device-found', (device) => {
    console.log('发现设备:', device.name);
  });
  await deviceManager.startScan({ timeout: 10000 });

  // 2. 连接打印机
  const printer = new BluetoothPrinter();
  const devices = deviceManager.getDiscoveredDevices();
  await printer.connect(devices[0].deviceId);

  // 3. 链式调用构建打印内容
  await printer
    .text('=== 欢迎光临 ===', 'GBK')
    .feed()
    .text('商品A     x1    ¥10.00', 'GBK')
    .text('商品B     x2    ¥20.00', 'GBK')
    .feed()
    .text('------------------------', 'GBK')
    .text('合计:            ¥30.00', 'GBK')
    .feed(2)
    .qr('https://example.com', { size: 6 })
    .feed(2)
    .cut()
    .print();

  await printer.disconnect();
}

支持的驱动

驱动协议典型品牌
EscPosESC/POS佳博、芯烨、商米、汉印
TsplDriverTSPLTSC ME240、TA210、TTP-244
ZplDriverZPLZebra ZD420、GT800、ZM400
CpclDriverCPCLHP IR3222、霍尼韦尔移动机
StarPrinterSTARSTAR TSP100、TSP700、TSP800
GPrinterDriver自定义佳博 GP-5890X 系列
XprinterDriverESC/POS芯烨 XP-58 系列
SprtDriverESC/POS思普瑞特系列

项目信息

npm versiondownloadslicensebuildstarsforks

为什么选择 taro-bluetooth-print?

  • 轻量级:gzip 后仅 ~15KB,无任何外部依赖
  • 高性能:智能分片 + 断点续传,弱网也能稳定打印
  • 多平台:一套 API,微信/支付宝/百度/字节/H5/鸿蒙/RN 全覆盖
  • 工业级驱动:ESC/POS、TSPL、ZPL、CPCL、StarPrinter 五大协议
  • 离线容灾:断网自动缓存,来网自动同步,零打印任务丢失

基于 MIT 许可发布