适用于Taro的蓝牙打印工具库,优化了图像处理和用户体验。
最新版本(1.0.8)优化了代码结构和性能,包括模块化重构、错误处理改进和构建流程优化。详见更新日志。
- 蓝牙热敏打印机连接和通信
- Web Worker处理图像和OCR任务
- 内存自动释放和资源管理
- 相机拍照和图像预处理
- 离线支持和PWA特性
- 完全支持Taro多端开发
npm install taro-bluetooth-print
import { BluetoothPrinter } from 'taro-bluetooth-print';
// 创建打印机实例
const printer = new BluetoothPrinter();
// 连接打印机
try {
const device = await printer.connectDeviceByName('打印机名称');
// 打印文本
await printer.printText('Hello World');
// 打印 ESC/POS 指令
const escCommand = new Uint8Array([0x1B, 0x40]); // ESC @ 初始化打印机
await printer.printEscCommand(escCommand);
} catch (error) {
console.error('打印错误:', error);
}
// 关闭连接
await printer.close();
详细 API 文档请参阅:API 文档
import { BluetoothPrinter } from 'taro-bluetooth-print';
// 创建打印机实例
const printer = new BluetoothPrinter();
// 连接打印机
try {
const device = await printer.connectDeviceByName('打印机名称');
// 打印文本
await printer.printText('Hello World');
// 打印 ESC/POS 指令
const escCommand = new Uint8Array([0x1B, 0x40]); // ESC @ 初始化打印机
await printer.printEscCommand(escCommand);
} catch (error) {
console.error('打印错误:', error);
}
// 关闭连接
await printer.close();
- 克隆仓库
git clone https://github.com/Agions/taro-bluetooth-print.git
cd taro-bluetooth-print
- 安装依赖
npm install
- 开发模式
npm run start
- 构建
npm run build
npm test
MIT License
欢迎提交 Issue 和 Pull Request!