1.0.1 • Published 2 years ago

cuboh-react-native-epson-epos-printer v1.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

react-native-epson-epos-printer

React native module to handle Epson ePOS SDK (for now, only Android)

npm version MIT License npm downloads install size npm version

🚀 Installation

Using npm:

npm i cuboh-react-native-epson-epos-printer

📖 Documentation

Tags:

The printing order is sequential and will go according to the payload.

Implementation

import Printer from 'cuboh-react-native-epson-epos-printer';
Printer.print(1, '50:57:9C:57:7B:M1', examplePayload)
                .then(console.log)
                .catch(console.log)

Setting the series of printer and the target language

default (TM_M10, English), it cloud specifies with Printer Series and Text Language.

Printer.setPrinterClass(printerSeries, textLanguage)

Controls the device discovery function

  • Update Manifest
// file: android/app/src/main/AndroidManifest.xml
...
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.BLUETOOTH"/>
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
...
  • Initialization
import {PrinterDiscover} from 'react-native-epson-epos-printer';
const discover = new PrinterDiscover()
  • Start
discover.start()
discover.on('discover', console.log)
  • Stop
discover.stop()

Different connection method

  • Connect by TCP
Printer.print(1, '50:57:9C:57:7B:M1', examplePayload)
Printer.print(1, '192.168.192.168', examplePayload)
  • Connect by USB
Printer.print(1, 'USB:', examplePayload)
Printer.print(1, 'USB:/dev/udev/*', examplePayload)
  • If discovery function has been running, it could auto choose the Printer.
Printer.print(1, 'auto', examplePayload)

In the case of USB interface, it is recommended that you obtain permission to access theUSB device in the application in advance. In the case of USB interface, it is recommended that you obtain permission to access theUSB device in the application in advance.

Enter the following code into the AndroidManifest.xml file.

<manifest ...>
    <application>
        <activity ...>
            <intent-filter>
                <action android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED" />
            </intent-filter>
            <meta-data android:name="android.hardware.usb.action.USB_DEVICE_ATTACHED"
              android:resource="@xml/device_filter" />
        </activity>
    </application>
</manifest>

Add the res/xml/device_filter.xml in resource file, enter the following code into the device_filter.xml file.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <usb-device vendor-id="1208" />
</resources>

📋 Commands

KeyTypeDescription
imageurllink to download the image. Alternatively, the size tag can be used to indicate the size of the image, by default the size is 187
linenumberspecifies the number of lines to skip. You can also use the text tag with new lines.
dottednumberspecifies the number of centered dotted lines. You can also use the centered tag with "------------------------------".
centeredstringcentered text.
textstringdefault text positioned to the left and add new line at the end. You can write a paragraph making line breaks with \n to avoid having to add several text tags.
leftstringwrite the text to the left without adding a new line. Using new lines can cause unexpected problems, to use a new line better use the text tag.
rightstringwrite the text to the right without adding a new line. left and right can be used in combination, when combined a new line will be added by default. Example:{ "left": "Celggar:", "right": "$33,024.01"}.
barcodestringprint a barcode. default (BARCODE_CODE93). Barcode Types
qrcodestring / arrayprint one or two QR code in a line.

Optional setting

text

KeyTypeDescriptionDefault
alignstringspecifies the alignment ("left", "right", "center").left
widthnumberspecifies the horizontal scaling of characters, integer from 1 to 8.1
heightnumberspecifies the vertical scaling of characters, integer from 1 to 8.1
smoothbooleanenables or disables smoothing.false
boldbooleanenables or disables the bold style.false
underscorebooleanenables or disables the underscore style.false

dotted

KeyTypeDescriptionDefault
amountnumberspecifies the number of dot of dotted lines.32

image

KeyTypeDescriptionDefault
alignstringspecifies the alignment ("left", "right", "center").center
sizenumberspecifies the size of the image (in pixels).187

barcode

KeyTypeDescriptionDefault
alignstringspecifies the alignment ("left", "right", "center").left
typenumberspecifies the Barcode Types.9(BARCODE_CODE93)
widthnumberspecifies the width of a single module in dots, integer from 2 to 6.2
heightnumberspecifies the height of the barcode in dots, integer from 1 to 255.50
HRIstringhuman readable interpretation, specifies the HRI position ("HRI_NONE", "HRI_ABOVE", "HRI_BELOW", "HRI_BOTH").HRI_NONE

qrcode

KeyTypeDescriptionDefault
alignstringspecifies the alignment ("left", "right", "center"). if the type of qrcode input is array, the alignment will be centered.left
sizenumberspecifies the size of the QR code (in pixels).187
shiftnumberonly for printing two QR code in a line specifies the size of the space area between both QR code (in pixels).20

📋 Barcode types

BarcodeValue
BARCODE_UPC_A0
BARCODE_UPC_E1
BARCODE_EAN132
BARCODE_JAN133
BARCODE_EAN84
BARCODE_JAN85
BARCODE_CODE396
BARCODE_ITF7
BARCODE_CODABAR8
BARCODE_CODE939
BARCODE_CODE12810
BARCODE_GS1_12811
BARCODE_GS1_DATABAR_OMNIDIRECTIONAL12
BARCODE_GS1_DATABAR_TRUNCATED13
BARCODE_GS1_DATABAR_LIMITED14
BARCODE_GS1_DATABAR_EXPANDED15

Printer Series

SeriesValue
TM_M100
TM_M301
TM_M30II2
TM_P203
TM_P604
TM_P60II5
TM_P806
TM_T207
TM_T608
TM_T709
TM_T8110
TM_T8211
TM_T8312
TM_T83III13
TM_T8814
TM_T9015
TM_T10016
TM_U22017
TM_U33018
TM_L9019
TM_H600020

Text Language

LanguageValue
English (ANK specification)0
Japanese1
Simplified Chinese2
Traditional Chinese3
Korean4
Thai (South Asian specification)5
Vietnamese (South Asian specification)6
Multiple languages (UTF-8)7

💻 Example Payload

sample 1

[
  {
    "image": "https://github.githubassets.com/images/modules/logos_page/Octocat.png",
    "align": "center"
  },
  {
    "line": 1
  },
  {
    "centered": "Celggar Company"
  },
  {
    "centered": "RUC 777-136-113133  DV  02"
  },
  {
    "centered": "Capellanía"
  },
  {
    "centered": "Express line 236-5555"
  },
  {
    "line": 2
  },
  {
    "text": "RUC/CIP: C-8-330124"
  },
  {
    "text": "SOCIAL: TODD MULLINS - 8733212"
  },
  {
    "line": 2
  },
  {
    "text": "INVOICE: 0-00000002401\nDOCUMENTO ERP: ACM1PT\nSUCURSAL: Capellanía - Principal\nSELLER: Celggar WEB\n NAME: Celggar"
  },
  {
    "line": 3
  },
  {
    "centered": "FECHA: 11/09/2020    HORA: 8:47"
  },
  {
    "barcode": "0-0000039242",
    "type": 9,
    "align": "center"
  },
  {
    "text": "COMMAND"
  },
  {
    "dotted": 2
  },
  {
    "text": "2.0 x $4.99"
  },
  {
    "text": "C000056297 Abono orgánico humus 40lb $9.98 1.0 x 10.99"
  },
  {
    "text": "C000056298 Rodillo para pintar $9.98 1.0 x 10.99"
  },
  {
    "text": "C000056299 Leche 40lb $9.98 1.0 x 10.99"
  },
  {
    "text": "C000007394 COSTO DE ENVÍO (ACARREO) $7.95"
  },
  {
    "left": "SUBTOTAL:",
    "right": "$109.10"
  },
  {
    "left": "DISCOUNT:",
    "right": "$0.0"
  },
  {
    "dotted": 1
  },
  {
    "left": "SUBTOTAL (again):",
    "right": "$109.10"
  },
  {
    "left": "EXEMPT:",
    "right": "$0.00"
  },
  {
    "left": "GRAVABLE:",
    "right": "$109.10"
  },
  {
    "left": "I.T.B.M.S (7%):",
    "right": "$5.38"
  },
  {
    "left": "TOTAL:",
    "right": "$114.48"
  },
  {
    "left": "PUNTOS C:",
    "right": "$7.83"
  },
  {
    "left": "CAMBIO:",
    "right": "$0"
  },
  {
    "dotted": 2
  },
  {
    "text": "DELIVERY ADDRESS"
  },
  {
    "dotted": 1
  },
  {
    "text": "Panamá, Coclé, Capellanía, Lex Luthor Tower, Apto ACM1PT 01A Calle Justice League - cerca de la cueva de Batman"
  },
  {
    "text": "COMMENTS: NO COMMENTS"
  },
  {
    "text": "EMAIL: lobezno33@jleague.com"
  },
  {
    "text": "PHONE: 236-5555"
  }
]

sample 2

[
  {
    "image": "https://github.githubassets.com/images/modules/logos_page/Octocat.png",
    "align": "center",
    "size": 150
  },
  {
    "text": "2021-JAN",
    "align": "center",
    "width": 2,
    "height": 2,
    "smooth": true,
    "bold": true,
    "underscore": true
  },
  {
    "text": "BK-12345678",
    "align": "center",
    "width": 2,
    "height": 2,
    "smooth": true,
    "bold": true
  },
  {
    "line": 1
  },
  {
    "text": "2021-01-23 12:34:56  type:25",
    "align": "left",
    "width": 1,
    "height": 1,
    "smooth": false,
    "bold": false
  },
  {
    "left":"code:000     total : $888"
  },
  {
    "line": 1
  },
  {
    "barcode":"1234567890",
    "type": 9,
    "align": "center",
    "width": 2,
    "height": 50,
    "HRI": "HRI_ABOVE"
  },
  {
    "qrcode":["left","rigt"],
    "size":200,
    "shift":20
  },
  {
    "dotted":1,
    "amount":40
  },
  {
    "line": 1
  },
  {
    "left":"USB",
    "right":"111 TX"
  },
  {
    "left":"TCP",
    "right":"777 TX"
  },
  {
    "right":"total : $888"
  },
  {
    "dotted":2,
    "amount":40
  },
  {
    "left":"Please keep your invoice and sales details properly, For commodity-related operations, please hold the invoice and sales details."
  }
]