taro-bluetooth-print
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

taro-bluetooth-print

适用于Taro的蓝牙打印工具库,优化了图像处理和用户体验。

最新版本

npm version

最新版本(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 文档请参阅: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();

开发指南

本地开发

  1. 克隆仓库
git clone https://github.com/Agions/taro-bluetooth-print.git
cd taro-bluetooth-print
  1. 安装依赖
npm install
  1. 开发模式
npm run start
  1. 构建
npm run build

测试

npm test

许可证

MIT License

贡献

欢迎提交 Issue 和 Pull Request!

Package Sidebar

Install

npm i taro-bluetooth-print

Weekly Downloads

79

Version

1.0.8

License

MIT

Unpacked Size

941 kB

Total Files

46

Last publish

Collaborators

  • agions