{"_id":"@cerikzhan/react-native-bluetooth-escpos-printer","name":"@cerikzhan/react-native-bluetooth-escpos-printer","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@cerikzhan/react-native-bluetooth-escpos-printer","version":"0.0.1","description":"React-Native plugin for the bluetooth ESC/POS printers.","main":"index.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"keywords":["react-native","ESC","POS","Bluetooth","Printer"],"author":{"name":"Serikzhan Naviy"},"license":"MIT","peerDependencies":{"react-native":">=0.55.4"},"types":"./index.d.ts","_id":"@cerikzhan/react-native-bluetooth-escpos-printer@0.0.1","gitHead":"3f1ecaf7ef958af3387456de299ea0e2451b401c","_nodeVersion":"20.11.0","_npmVersion":"10.2.4","dist":{"integrity":"sha512-UIUslSmFVYj7kBmw0Mo45s2SMQkhTMbeyT5FVOupeyvUWQf05eqj27QsFc1ZpGg1k6M9yjE99AUn8ka5PEapBA==","shasum":"9db06f3ec034e0953feed28ebfc31d5267b22cb6","tarball":"https://registry.npmjs.org/@cerikzhan/react-native-bluetooth-escpos-printer/-/react-native-bluetooth-escpos-printer-0.0.1.tgz","fileCount":512,"unpackedSize":2650628,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDdkuYmQg4V+KHcwYNxUJ5a1QDZeOo7A4Nue+P976bAXwIgFLzrADlaP4TRGLFr2Lmx77l7xz8moa9ButlKG7SsT20="}]},"_npmUser":{"name":"cerikzhan","email":"seriknavii@gmail.com"},"directories":{},"maintainers":[{"name":"cerikzhan","email":"seriknavii@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/react-native-bluetooth-escpos-printer_0.0.1_1734082493785_0.5448295470558941"},"_hasShrinkwrap":false}},"time":{"created":"2024-12-13T09:34:53.702Z","0.0.1":"2024-12-13T09:34:54.034Z","modified":"2024-12-13T09:34:54.280Z"},"maintainers":[{"name":"cerikzhan","email":"seriknavii@gmail.com"}],"description":"React-Native plugin for the bluetooth ESC/POS printers.","keywords":["react-native","ESC","POS","Bluetooth","Printer"],"author":{"name":"Serikzhan Naviy"},"license":"MIT","readme":"# react-native-bluetooth-escpos-printer\n\nReact-Native plugin for the bluetooth ESC/POS & TSC printers.\n\nAny questions or bug please raise a issue.\n\n##Still under developement\n\n#May support Android /IOS\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/januslo/react-native-bluetooth-escpos-printer/master/LICENSE) [![npm version](https://badge.fury.io/js/react-native-bluetooth-escpos-printer.svg)](https://www.npmjs.com/package/react-native-bluetooth-escpos-printer)\n\n## Installation\n### Step 1 ###\nInstall via NPM [Check In NPM](https://www.npmjs.com/package/react-native-bluetooth-escpos-printer)\n```bash\nnpm install react-native-bluetooth-escpos-printer --save\n```\n\nOr install via github\n```bash\nnpm install https://github.com/januslo/react-native-bluetooth-escpos-printer.git --save\n```\n\n### Step2 ###\nLink the plugin to your RN project\n```bash\nreact-native link react-native-bluetooth-escpos-printer\n```\n\n### Manual linking (Android) ###\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/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\n\n### Step3 ###\nRefers to your JS files\n```javascript\n    import {BluetoothManager,BluetoothEscposPrinter,BluetoothTscPrinter} from 'react-native-bluetooth-escpos-printer';\n```\n\n## Usage and APIs ##\n\n### BluetoothManager ###\nBluetoothManager is the module for Bluetooth service management, supports Bluetooth status check, enable/disable Bluetooth service, scan devices, connect/unpair devices.\n\n* isBluetoothEnabled ==>\nasync function, checks whether Bluetooth service is enabled.\n//TODO: consider to return the the devices information already bound and paired here..\n\n```javascript\n     BluetoothManager.isBluetoothEnabled().then((enabled)=> {\n                alert(enabled) // enabled ==> true /false\n            }, (err)=> {\n                alert(err)\n            });\n```\n\n* enableBluetooth ==> ``` diff + ANDROID ONLY ```\nasync function, enables the bluetooth service, returns the devices information already bound and paired.  ``` diff - IOS would just resovle with nil ```\n\n```javascript\nBluetoothManager.enableBluetooth().then((r)=>{\n                var paired = [];\n                if(r && r.length>0){\n                    for(var i=0;i<r.length;i++){\n                        try{\n                            paired.push(JSON.parse(r[i])); // NEED TO PARSE THE DEVICE INFORMATION\n                        }catch(e){\n                            //ignore\n                        }\n                    }\n                }\n                console.log(JSON.stringify(paired))\n            },(err)=>{\n               alert(err)\n           });\n```\n\n* disableBluetooth ==>  ``` diff + ANDROID ONLY ```\nasync function ,disables the bluetooth service. ``` diff - IOS would just resovle with nil ```\n\n```javascript\nBluetoothManager.disableBluetooth().then(()=>{\n            // do something.\n          },(err)=>{alert(err)});\n```\n\n* scanDevices ==>\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\n DeviceEventEmitter.addListener(\n            BluetoothManager.EVENT_DEVICE_ALREADY_PAIRED, (rsp)=> {\n                this._deviceAlreadPaired(rsp) // rsp.devices would returns the paired devices array in JSON string.\n            });\n        DeviceEventEmitter.addListener(\n            BluetoothManager.EVENT_DEVICE_FOUND, (rsp)=> {\n                this._deviceFoundEvent(rsp) // rsp.devices would returns the found device object in JSON string\n            });\n```\n\nsamples with scanDevices function\n```javascript\nBluetoothManager.scanDevices()\n            .then((s)=> {\n                var ss = JSON.parse(s);//JSON string\n                this.setState({\n                    pairedDs: this.state.pairedDs.cloneWithRows(ss.paired || []),\n                    foundDs: this.state.foundDs.cloneWithRows(ss.found || []),\n                    loading: false\n                }, ()=> {\n                    this.paired = ss.paired || [];\n                    this.found = ss.found || [];\n                });\n            }, (er)=> {\n                this.setState({\n                    loading: false\n                })\n                alert('error' + JSON.stringify(er));\n            });\n```\n\n* connect ==>\nasync function, connects the specified device, if not bound, bound dailog prompts.\n\n```javascript\n\n    BluetoothManager.connect(rowData.address) // the device address scanned.\n     .then((s)=>{\n       this.setState({\n        loading:false,\n        boundAddress:rowData.address\n    })\n    },(e)=>{\n       this.setState({\n         loading:false\n     })\n       alert(e);\n    })\n\n```\n\n* unpair ==>\nasync function, disconnects and unpairs the specified devices\n\n```javascript\n     BluetoothManager.connect(rowData.address)\n     .then((s)=>{\n        //success here\n     },\n     (err)=>{\n        //error here\n     })\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 ###\nThe printer for label printing.\n\n* printLabel ==>\nasync function that performs the label print action.\n\n```javascript\nBluetoothTscPrinter.printLabel(options)\n.then(()=>{\n    //success\n},\n(err)=>{\n    //error\n})\n\n```\n\n#### Options of printLabel( ) function: (JSON object) ####\n\n##### width #####\n    label width , the real size of the label, measured by mm usually.\n##### height #####\n    label height, the real size of the label, measured by mm usually.\n##### direction #####\n    the printing direction, constants of BluetoothTscPrinter.DIRECTION, values BluetoothTscPrinter.DIRECTION.FORWARD/BluetoothTscPrinter.DIRECTION.BACKWARD (0/1)\n##### gap #####\n    the gap between 2 labels, measured by mm usually.\n##### reference #####\n    the \"zero\" position of the label, values [x,y], default [0,0]\n##### tear #####\n    switch of the paper cut, constants of BluetoothTscPrinter.TEAR, values ON/OFF (string 'ON','OFF')\n##### sound #####\n    switch of the bee sound, values 0/1\n##### text #####\n    the collection of texts to print, contains following fields as the configuration:\n        * text\n            the text string,\n        * x\n            the text print start position-x\n        * y\n            the text print start position-y\n        * fonttype\n            the font type of the text, constanst of BluetoothTscPrinter.FONTTYPE,refereces as table:\n                | CONSTANTS | VALUE   |\n                |---|---|\n                |FONT_1| \"1\"|\n                |FONT_2| \"2\"|\n                |FONT_3| \"3\"|\n                |FONT_4| \"4\"|\n                |FONT_5| \"5\"|\n                |FONT_6| \"6\"|\n                |FONT_7| \"7\"|\n                |FONT_8|\"8\"|\n                |SIMPLIFIED_CHINESE| \"TSS24.BF2\"|\n                |TRADITIONAL_CHINESE| \"TST24.BF2\"|\n                |KOREAN| \"K\"|\n        * rotation\n            the rotation of the text, constants of the BluetoothTscPrinter.ROTATION, referces as table:\n                   | CONSTANTS | VALUE   |\n                   |---|---|\n                   |ROTATION_0| 0|\n                   |ROTATION_90| 90|\n                   |ROTATION_180| 180|\n                   |ROTATION_270| 270|\n        * xscal\n            the scal in x,\n        * yscal\n            the scal in y, xscal/yscal is the constants of the BluetoothTscPrinter.FONTMUL, referces as table:\n             | CONSTANTS | VALUE   |\n             |---|---|\n             |MUL_1| 1|\n             |MUL_2| 2|\n             |MUL_3| 3|\n             |MUL_4| 4|\n             |MUL_5| 5|\n             |MUL_6| 6|\n             |MUL_7| 7|\n             |MUL_8| 8|\n             |MUL_9| 9|\n             |MUL_10: 10|\n\n##### qrcode #####\n    the collection of qrcodes to print, contains following fields as the configuration:\n        * code\n            the qrcode content string.\n        * x\n            the print start position at x\n        * y\n            the print start position at y\n        * level\n            the error correction level, constants of BluetoothTscPrinter.EEC, referces as tables:\n            | CONSTANTS | VALUE   |\n            |---|---|\n            |LEVEL_L|\"L\"|\n            |LEVEL_M| \"M\"|\n            |LEVEL_Q| \"Q\"|\n            |LEVEL_H| \"H\"|\n        * width\n            the qrcode size (width X width),since the qrcode are square normally, so we just config the width.\n\n        * rotation\n            rotation. the same as text object.\n\n##### barcode #####\n    the collection of barcode to print, contains following fields as configuration\n      * x\n        the print start position of x,\n      * y\n        the print start position of y,\n      * type\n        the barcode type, constants of BluetoothTscPrinter, definition as table:\n        | CONSTRANTS | VALUE |\n        |---|---|\n        | CODE128 | \"128\" |\n        | CODE128M | \"128M\" |\n        | EAN128 | \"EAN128\" |\n        | ITF25 | \"25\" |\n        | ITF25C | \"25C\" |\n        | CODE39 | \"39\" |\n        | CODE39C | \"39C\" |\n        | CODE39S | \"39S\" |\n        | CODE93 | \"93\" |\n        | EAN13 | \"EAN13\" |\n        | EAN13_2 | \"EAN13+2\" |\n        | EAN13_5 | \"EAN13+5\" |\n        | EAN8 | \"EAN8\" |\n        | EAN8_2 | \"EAN8+2\" |\n        | EAN8_5 | \"EAN8+5\" |\n        | CODABAR | \"CODA\" |\n        | POST | \"POST\" |\n        | UPCA | \"EAN13\" |\n        | UPCA_2 | \"EAN13+2\" |\n        | UPCA_5 | \"EAN13+5\" |\n        | UPCE | \"EAN13\" |\n        | UPCE_2 | \"EAN13+2\" |\n        | UPCE_5 | \"EAN13+5\" |\n        | CPOST | \"CPOST\" |\n        | MSI | \"MSI\" |\n        | MSIC | \"MSIC\" |\n        | PLESSEY | \"PLESSEY\" |\n        | ITF14 | \"ITF14\" |\n        | EAN14 | \"EAN14\" |\n\n     * height\n      the height of the barcode.\n     * readable\n      the human readable factor, 0-not readable, 1-readable.\n     * rotation\n      rotation, the same as text.\n     * code\n      the code to generate and print, should follow the restriction of the code type using.\n     * wide\n     the wide bar lines width (dot)\n     * narrow\n     the narrow bar line width (dot)\n\n##### image #####\n    the collection of the image to print.\n     * x\n     the print start position x.\n     * y\n     the print start position y.\n     * mode\n     the bitmap mode of print, constants of BluetoothTscPrinter.BITMAP_MODE, valuse OVERWRITE(0),OR(1),XOR(2).\n     * width\n     the width of the image to print. (height will be calculated by image ratio)\n     * image\n     the base64 encoded image data(without schema)\n\n#### demo of printLabel() options ####\n```javascript\nlet 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       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       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   qrcode: [{x: 20, y: 96, level: BluetoothTscPrinter.EEC.LEVEL_L, width: 3, rotation: BluetoothTscPrinter.ROTATION.ROTATION_0, code: 'show me the money'}],\n   barcode: [{x: 120, y:96, type: BluetoothTscPrinter.BARCODETYPE.CODE128, height: 40, readable: 1, rotation: BluetoothTscPrinter.ROTATION.ROTATION_0, code: '1234567890'}],\n   image: [{x: 160, y: 160, mode: BluetoothTscPrinter.BITMAP_MODE.OVERWRITE,width: 60,image: base64Image}]\n}\n```\n### BluetoothEscposPrinter ###\n  the printer for receipt printing, following ESC/POS command.\n\n#### printerInit() ####\n  init the printer.\n\n#### printAndFeed(int feed) ####\n  printer the buffer data and feed (feed lines).\n\n#### printerLeftSpace(int sp) ####\n  set the printer left spaces.\n\n#### printerLineSpace(int sp) ####\n  set the spaces between lines.\n\n#### printerUnderLine(int line) ####\n  set the underline of the text, @param line --  0-off,1-on,2-deeper\n\n#### printerAlign(int align) ####\n  set the printer alignment, constansts: BluetoothEscposPrinter.ALIGN.LEFT/BluetoothEscposPrinter.ALIGN.CENTER/BluetoothEscposPrinter.ALIGN.RIGHT.\n  Does not work on printPic() method.\n\n#### printText(String text, ReadableMap options) ####\n  print text, options as following:\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(ReadableArray columnWidths,ReadableArray columnAligns,ReadableArray columnTexts,ReadableMap options) ####\n  print texts in column, Parameters as following:\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(int width) ####\n  sets the width of the printer.\n\n#### printPic(String base64encodeStr,ReadableMap options) ####\n  prints the image which is encoded by base64, without schema.\n  * options: 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#### setfTest() ####\n  prints the self test.\n\n#### rotate() ####\n  sets the rotation of the line.\n\n#### setBlob(int weight) ####\n  sets blob of the line.\n\n#### printQRCode(String content, int size, int correctionLevel) ####\n  prints the qrcode.\n\n#### printBarCode(String str,int nType, int nWidthX, int nHeight, int nHriFontType, int nHriFontPosition) ####\n  prints the barcode.\n\n### Demos of printing a receipt ###\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'],{});\n    await  BluetoothEscposPrinter.printText(\"\\n\\r\",{});\n  await 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);\n```\n\n### Demo for opening the drawer ###\n```javascript\nBluetoothEscposPrinter.opendDrawer(0, 250, 250);\n```\n","readmeFilename":"README.md"}