{"id":23197739,"url":"https://github.com/letstri/react-native-bluetooth-escpos-printer","last_synced_at":"2025-08-18T23:32:17.335Z","repository":{"id":61740256,"uuid":"354664645","full_name":"letstri/react-native-bluetooth-escpos-printer","owner":"letstri","description":null,"archived":false,"fork":false,"pushed_at":"2022-10-20T08:38:09.000Z","size":95260,"stargazers_count":5,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-16T18:12:49.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/letstri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-04T23:07:39.000Z","updated_at":"2024-01-07T16:58:14.000Z","dependencies_parsed_at":"2022-10-20T16:15:25.627Z","dependency_job_id":null,"html_url":"https://github.com/letstri/react-native-bluetooth-escpos-printer","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letstri%2Freact-native-bluetooth-escpos-printer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letstri%2Freact-native-bluetooth-escpos-printer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letstri%2Freact-native-bluetooth-escpos-printer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/letstri%2Freact-native-bluetooth-escpos-printer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/letstri","download_url":"https://codeload.github.com/letstri/react-native-bluetooth-escpos-printer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230287133,"owners_count":18202808,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-18T14:37:14.165Z","updated_at":"2024-12-18T14:37:14.943Z","avatar_url":"https://github.com/letstri.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @brooons/react-native-bluetooth-escpos-printer\n\n\u003e Cloned and changed from https://github.com/januslo/react-native-bluetooth-escpos-printer\n\n[![npm version](https://badge.fury.io/js/%40brooons%2Freact-native-bluetooth-escpos-printer.svg)](https://www.npmjs.com/package/@brooons/react-native-bluetooth-escpos-printer)\n\nReact-Native plugin for the bluetooth ESC/POS \u0026 TSC printers.\n\nAny questions or bug please raise a issue.\n\n## Features\n\n- Still under development\n- May support Android only\n- Typescript support\n\n## Table of Contents\n\n- [Installation](#installation)\n- [Usage and APIs](#usage-and-apis)\n  - [BluetoothManager](#bluetoothmanager)\n  - [BluetoothTscPrinter](#bluetoothtscprinter)\n  - [BluetoothEscposPrinter](#bluetoothescposprinter)\n\n## Installation\n\n### Step 1\n\nInstall via NPM [Check In NPM](https://www.npmjs.com/package/@brooons/react-native-bluetooth-escpos-printer)\n\n```bash\nnpm install @brooons/react-native-bluetooth-escpos-printer --save\n```\n\n### Step 2\n\nLink the plugin to your RN project\n\n```bash\nreact-native link @brooons/react-native-bluetooth-escpos-printer\n```\n\n### Manual linking (Android)\n\nEnsure your build files match the following requirements:\n\n1. (React Native 0.59 and lower) Define the *`react-native-bluetooth-escpos-printer`* project in *`android/settings.gradle`*:\n\n```\ninclude ':react-native-bluetooth-escpos-printer'\nproject(':react-native-bluetooth-escpos-printer').projectDir = new File(rootProject.projectDir, '../node_modules/@brooons/react-native-bluetooth-escpos-printer/android')\n```\n2. (React Native 0.59 and lower) Add the *`react-native-bluetooth-escpos-printer`* as an dependency of your app in *`android/app/build.gradle`*:\n```\n...\ndependencies {\n  ...\n  implementation project(':react-native-bluetooth-escpos-printer')\n}\n```\n\n3. (React Native 0.59 and lower) Add *`import cn.jystudio.bluetooth.RNBluetoothEscposPrinterPackage;`* and *`new RNBluetoothEscposPrinterPackage()`* in your *`MainApplication.java`* :\n\n### Step 3\n\nRefers to your JS files\n\n```javascript\nimport { BluetoothManager, BluetoothEscposPrinter, BluetoothTscPrinter } from '@brooons/react-native-bluetooth-escpos-printer';\n```\n\n## Usage and APIs\n\n### BluetoothManager\n\nBluetoothManager is the module for Bluetooth service management, supports Bluetooth status check, enable/disable Bluetooth service, scan devices, connect/unpair devices.\n\n#### checkBluetoothEnabled(): Promise\u003cvoid\u003e\n\nAsync function, checks whether Bluetooth service is enabled.\n\n\u003e // TODO: consider to return the the devices information already bound and paired here..\n\n```javascript\nconst isEnabled = await BluetoothManager.checkBluetoothEnabled();\n\nconsole.log(isEnabled); // true/false\n```\n\n#### enableBluetooth(): Promise\u003cvoid\u003e\n\nAsync function, enables the bluetooth service, returns the devices information already bound and paired.\n\n```javascript\nconst devices = await BluetoothManager.enableBluetooth();\n\nreturn devices\n  .reduce((acc, device) =\u003e {\n    try {\n      return [...acc, JSON.parse(device)];\n    } catch (e) {\n      return acc;\n    }\n  }, [])\n  .filter((device) =\u003e device.address);\n```\n\n#### disableBluetooth(): Promise\u003cvoid\u003e\n\nAsync function, disables the bluetooth service.\n\n```javascript\nawait BluetoothManager.disableBluetooth();\n```\n\n#### scanDevices(): Promise\u003cvoid\u003e\n\nAsync function, scans the bluetooth devices, returns devices found and paired after scan finish. Event [BluetoothManager.EVENT_DEVICE_ALREADY_PAIRED] would be emitted with devices bound; event [BluetoothManager.EVENT_DEVICE_FOUND] would be emitted (many time) as long as new devices found.\n\nsamples with events:\n```javascript\nDeviceEventEmitter.addListener(\n  BluetoothManager.EVENT_DEVICE_ALREADY_PAIRED, (response) =\u003e {\n    console.log(response);\n    // response.devices would returns the paired devices array in JSON string.\n  }\n);\nDeviceEventEmitter.addListener(\n  BluetoothManager.EVENT_DEVICE_FOUND, (response) =\u003e {\n    console.log(response);\n    // response.devices would returns the found device object in JSON string\n  }\n);\n```\n\nSample with scanDevices function\n\n```javascript\nconst {\n  found,\n  paired,\n}: {\n  found: Array\u003c{ address: string; name?: string }\u003e;\n  paired: Device[];\n} = JSON.parse(await BluetoothManager.scanDevices());\n\nreturn {\n  paired,\n  found: found.filter((device) =\u003e !!device.name),\n};\n```\n\n#### connect(address: string): Promise\u003cvoid\u003e\nasync function, connects the specified device, if not bound, bound dailog prompts.\n\n```javascript\nawait BluetoothManager.connect(address);\n```\n\n#### disconnect(address: string): Promise\u003cvoid\u003e\nasync function, disconnects the specified device.\n\n```javascript\nawait BluetoothManager.disconnect(address);\n```\n\n#### getConnectedDeviceAddress(): Promise\u003cvoid\u003e\nasync function, Return the address of the currently connected device .\n\n```javascript\nawait BluetoothManager.getConnectedDeviceAddress();\n```\n\n#### unpair(address: string): Promise\u003cvoid\u003e\nasync function, disconnects and unpairs the specified devices\n\n```javascript\nawait BluetoothManager.unpair(address);\n```\n\n#### Events of BluetoothManager module\n\n| Name/KEY | DESCRIPTION |\n|---|---|\n| EVENT_DEVICE_ALREADY_PAIRED | Emits the devices array already paired |\n| EVENT_DEVICE_DISCOVER_DONE | Emits when the scan done |\n| EVENT_DEVICE_FOUND | Emits when device found during scan |\n| EVENT_CONNECTION_LOST | Emits when device connection lost |\n| EVENT_UNABLE_CONNECT | Emits when error occurs while trying to connect device |\n| EVENT_CONNECTED | Emits when device connected |\n| EVENT_BLUETOOTH_NOT_SUPPORT | Emits when device not support bluetooth(android only) |\n\n### BluetoothTscPrinter\n\nThe printer for label printing.\n\n#### printLabel(): Promise\u003cvoid\u003e\n\nAsync function that performs the label print action.\n\n```javascript\nawait BluetoothTscPrinter.printLabel(options);\n```\n\n##### Options\n\n```typescript\ninterface IPrintLabelOptions {\n  width?: number;\n  height?: number;\n  gap?: number;\n  direction?: DIRECTION;\n  reference?: [number, number];\n  tear?: TEAR,\n  sound?: number,\n  text?: Array\u003c{\n    text: string;\n    x: number;\n    y: number;\n    fonttype: FONTTYPE;\n    rotation: ROTATION;\n    xscal: FONTMUL;\n    yscal: FONTMUL;\n  }\u003e;\n  qrcode?: Array\u003c{\n    x: number;\n    y: number;\n    level: EEC;\n    width: number;\n    rotation: ROTATION;\n    code: string;\n  }\u003e;\n  barcode?: Array\u003c{\n    x: number;\n    y: number;\n    type: BARCODETYPE;\n    height: number;\n    readable: number;\n    rotation: ROTATION;\n    code: string;\n  }\u003e;\n  image?: Array\u003c{\n    x: number;\n    y: number;\n    mode: BITMAP_MODE,\n    width: number,\n    image: string;\n  }\u003e;\n}\n```\n\n##### Demo of printLabel()\n\n```javascript\nconst base64Image = 'some_base_64';\n\nconst options = {\n  width: 40,\n  height: 30,\n  gap: 20,\n  direction: BluetoothTscPrinter.DIRECTION.FORWARD,\n  reference: [0, 0],\n  tear: BluetoothTscPrinter.TEAR.ON,\n  sound: 0,\n  text: [\n    {\n      text: 'I am a testing txt',\n      x: 20,\n      y: 0,\n      fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,\n      rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,\n      xscal:BluetoothTscPrinter.FONTMUL.MUL_1,\n      yscal: BluetoothTscPrinter.FONTMUL.MUL_1,\n    },\n    {\n      text: '你在说什么呢?',\n      x: 20,\n      y: 50,\n      fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,\n      rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,\n      xscal:BluetoothTscPrinter.FONTMUL.MUL_1,\n      yscal: BluetoothTscPrinter.FONTMUL.MUL_1,\n    },\n  ],\n  qrcode: [\n    {\n      x: 20,\n      y: 96,\n      level: BluetoothTscPrinter.EEC.LEVEL_L,\n      width: 3,\n      rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,\n      code: 'show me the money',\n    },\n  ],\n  barcode: [\n    {\n      x: 120,\n      y: 96,\n      type: BluetoothTscPrinter.BARCODETYPE.CODE128,\n      height: 40,\n      readable: 1,\n      rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,\n      code: '1234567890',\n    },\n  ],\n  image: [\n    {\n      x: 160,\n      y: 160,\n      mode: BluetoothTscPrinter.BITMAP_MODE.OVERWRITE,\n      width: 60,\n      image: base64Image,\n    },\n  ],\n};\n```\n### BluetoothEscposPrinter\n\nthe printer for receipt printing, following ESC/POS command.\n\n#### printerInit(): Promise\u003cvoid\u003e\n\nInit the printer.\n\n#### printAndFeed(feed: number): Promise\u003cvoid\u003e\n\nPrinter the buffer data and feed (feed lines).\n\n#### printerLeftSpace(space: number): Promise\u003cvoid\u003e\n\nSet the printer left spaces.\n\n#### printerLineSpace(space: number): Promise\u003cvoid\u003e\n\nSet the spaces between lines.\n\n#### printerUnderLine(line: number): Promise\u003cvoid\u003e\n\nSet the underline of the text.\n\n- 0 - off\n- 1 - on\n- 2 - deeper\n\n#### printerAlign(align: number): Promise\u003cvoid\u003e\n\nSet the printer alignment.\n\nConstansts:\n- BluetoothEscposPrinter.ALIGN.LEFT\n- BluetoothEscposPrinter.ALIGN.CENTER\n- BluetoothEscposPrinter.ALIGN.RIGHT\n\nDoes not work on printPic() method.\n\n#### printText(text: string, options: object): Promise\u003cvoid\u003e\n\nPrint text.\n\nOptions as following:\n\n- encoding - text encoding, default `GBK`.\n- codepage - codepage using, default `0`.\n- widthtimes - text font mul times in width, default `0`.\n- heigthTimes - text font mul times in height, default `0`.\n- fonttype - text font type, default `0`.\n\n#### printColumn(columnWidths: Array\u003cnumber\u003e, columnAligns: Array\u003cnumber\u003e, columnTexts: Array\u003cstring\u003e, options: object: Promise\u003cvoid\u003e\n\nPrint texts in column, Parameters as following:\n\n- columnWidths - int arrays, configs the width of each column, calculate by english character length. ex:the width of \"abcdef\" is 5 ,the width of \"中文\" is 4.\n- columnAligns - arrays, alignment of each column, values is the same of printerAlign().\n- columnTexts - arrays, the texts of each colunm to print.\n- options - text print config options, the same of printText() options.\n\n#### setWidth(width: number): Promise\u003cvoid\u003e\n\nSets the width of the printer.\n\nConstansts:\n- BluetoothEscposPrinter.DEVICE_WIDTH.WIDTH_58\n- BluetoothEscposPrinter.DEVICE_WIDTH.WIDTH_80\n\n#### printPic(base64encodeStr: string, options: object): Promise\u003cvoid\u003e\n\nPrints the image which is encoded by base64, without schema.\n\nOptions contains the params that may use in printing pic: \"width\": the pic width, basic on devices width(dots,58mm-384); \"left\": the left padding of the pic for the printing position adjustment.\n\n#### selfTest(): Promise\u003cvoid\u003e\n\nPrinter self test.\n\n#### rotate(): Promise\u003cvoid\u003e\n\nSets the rotation of the line.\n\n#### setBlob(weight: number): Promise\u003cvoid\u003e\n\nSets blob of the line.\n\n#### printQRCode(content: string, size: number, correctionLevel: number): Promise\u003cvoid\u003e\n\nPrints the QRCode.\n\n#### printBarCode(str: string, nType: number, nWidthX: number, nHeight: number, nHriFontType: number, nHriFontPosition: number): Promise\u003cvoid\u003e\n\nPrints the barcode.\n\n#### cutOnePoint(): Promise\u003cvoid\u003e\n\nCut a paper.\n\n#### Demos of printing a receipt\n\n```javascript\nawait BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);\nawait BluetoothEscposPrinter.setBlob(0);\nawait BluetoothEscposPrinter.printText(\"广州俊烨\\n\\r\",{\n  encoding: 'GBK',\n  codepage: 0,\n  widthtimes: 3,\n  heigthtimes: 3,\n  fonttype: 1,\n});\nawait BluetoothEscposPrinter.setBlob(0);\nawait BluetoothEscposPrinter.printText(\"销售单\\n\\r\",{\n  encoding: 'GBK',\n  codepage: 0,\n  widthtimes: 0,\n  heigthtimes: 0,\n  fonttype: 1,\n});\nawait BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT);\nawait BluetoothEscposPrinter.printText(\"客户：零售客户\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"单号：xsd201909210000001\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"日期：\"+(dateFormat(new Date(), \"yyyy-mm-dd h:MM:ss\"))+\"\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"销售员：18664896621\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"--------------------------------\\n\\r\",{});\nlet columnWidths = [12,6,6,8];\nawait BluetoothEscposPrinter.printColumn(columnWidths,\n  [BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.CENTER,BluetoothEscposPrinter.ALIGN.CENTER,BluetoothEscposPrinter.ALIGN.RIGHT],\n  [\"商品\",'数量','单价','金额'],{});\nawait BluetoothEscposPrinter.printColumn(columnWidths,\n  [BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.CENTER,BluetoothEscposPrinter.ALIGN.RIGHT],\n  [\"React-Native定制开发我是比较长的位置你稍微看看是不是这样?\",'1','32000','32000'],{});\nawait BluetoothEscposPrinter.printText(\"\\n\\r\",{});\nawait BluetoothEscposPrinter.printColumn(columnWidths,\n  [BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.CENTER,BluetoothEscposPrinter.ALIGN.RIGHT],\n  [\"React-Native定制开发我是比较长的位置你稍微看看是不是这样?\",'1','32000','32000'],{});\nawait BluetoothEscposPrinter.printText(\"\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"--------------------------------\\n\\r\",{});\nawait BluetoothEscposPrinter.printColumn([12,8,12],\n  [BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.LEFT,BluetoothEscposPrinter.ALIGN.RIGHT],\n  [\"合计\",'2','64000'],{});\nawait BluetoothEscposPrinter.printText(\"\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"折扣率：100%\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"折扣后应收：64000.00\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"会员卡支付：0.00\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"积分抵扣：0.00\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"支付金额：64000.00\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"结算账户：现金账户\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"备注：无\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"快递单号：无\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"打印时间：\"+(dateFormat(new Date(), \"yyyy-mm-dd h:MM:ss\"))+\"\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"--------------------------------\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"电话：\\n\\r\",{});\nawait BluetoothEscposPrinter.printText(\"地址:\\n\\r\\n\\r\",{});\nawait BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);\nawait BluetoothEscposPrinter.printText(\"欢迎下次光临\\n\\r\\n\\r\\n\\r\",{});\nawait BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.LEFT);\nawait BluetoothEscposPrinter.cutOnePoint();\n```\n\n#### Demo for opening the drawer\n\n```javascript\nBluetoothEscposPrinter.openDrawer(0, 250, 250);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletstri%2Freact-native-bluetooth-escpos-printer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fletstri%2Freact-native-bluetooth-escpos-printer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fletstri%2Freact-native-bluetooth-escpos-printer/lists"}