@hendrysetiadi/react-native-sunmi-printer
v0.2.0
Published
React Native Library for SUNMI Inner Printer
Maintainers
Readme
react-native-sunmi-printer
React Native Library for SUNMI Inner Printer (Android only)
Installation
npm install @hendrysetiadi/react-native-sunmi-printerUsage
import SunmiPrinter from '@hendrysetiadi/react-native-sunmi-printer';
// or ES6+ destructured imports
import { initPrinter } from '@hendrysetiadi/react-native-sunmi-printer';API
getPrinterSerialNo()
getPrinterSerialNo(): Promise<string>
Examples
const serialNo = await SunmiPrinter.getPrinterSerialNo();getPrinterModel()
getPrinterModel(): Promise<string>
Examples
const printerModel = await SunmiPrinter.getPrinterModel();getPrinterVersion()
getPrinterVersion(): Promise<string>
Examples
const printerVersion = await SunmiPrinter.getPrinterVersion();getPrinterPaper()
getPrinterPaper(): Promise<string>
Examples
const printerPaper = await SunmiPrinter.getPrinterPaper();initPrinter()
initPrinter(): Promise<null>
Initialize printer and reset printer state (font size, alignment, etc.), should be called first before the print call
Examples
await SunmiPrinter.getPrinterPaper();printLineWrap()
printLineWrap(n: number) : Promise<null>
Print Paper Feed after finishing the Previous printing content
Parameters
- n : Number of Lines
Examples
await SunmiPrinter.printLineWrap(3);feedPaper()
feedPaper() : Promise<null>
Feed the paper automatically according to the distance between the paper hatch and the print head. If the device does not support, then replaced by printing three lines
Examples
await SunmiPrinter.feedPaper();setAlignment()
setAlignment(alignment: number) : Promise<null>
Set the Printing Alignment (Setting the printing alignment will affect subsequent printing unless it is initialized)
Parameters
- alignment : Alignment Mode (0 = Left, 1 = Center, 2 = Right)
Examples
// Set Alignment to Center
await SunmiPrinter.setAlignment(1);setFontSize()
setFontSize(fontSize: number) : Promise<null>
Set the Printing Font Size (Setting the font size will affect subsequent printing unless it is initialized). Adjusting the font size will affect the character width and the number of characters per line
Examples
await SunmiPrinter.setFontSize(32);printText()
printText(content: string) : Promise<null>
Parameters
- content : Text to Print
Examples
await SunmiPrinter.printText('Hello World');printTextWithOption()
printTextWithOption(content: string, fontSize: number, isBold: boolean, isUnderline: boolean) : Promise<null>
Print Text with Size, Bold, and Underline options
Parameters
- content : Text to Print
- fontSize
- isBold
- isUnderline
Examples
await SunmiPrinter.printTextWithOption('Hello World', 24, true, true);printTextTable()
printTextTable(contentArray: string[], widthArray: number[], alignmentArray: number[]) : Promise<null>
Print Text in a form of Table (can specify the column Width and Alignment)
Parameters
- contentArray : Array of Text for each Column
- widthArray : Array of Width ratio for each Column
- alignmentArray : Array of Alignment for each Column (0 = Left, 1 = Center, 2 = Right)
Examples
await SunmiPrinter.printTextTable(
['Date', 'Jan 1st, 10:00 AM'],
[1, 1],
[0, 2]
);printBarcode()
printBarcode(data: string, symbology: number, height: number, width: number, textPosition: number) : Promise<null>
Print One-Dimensional Barcode
Parameters
- data : Barcode data
- symbology : Barcode Type
- 0 = UPC-A
- 1 = UPC-E
- 2 = JAN13(EAN13)
- 3 = JAN8(EAN8)
- 4 = CODE39
- 5 = ITF
- 6 = CODABAR
- 7 = CODE93
- 8 = CODE128
- height : Barcode Height (1 - 255)
- width : Barcode Width (2 - 6)
- textPosition : Barcode Text Position
- 0 = No Text
- 1 = Text above the Barcode
- 2 = Text below the Barcode
- 3 = Text both above and below the Barcode
Examples
await SunmiPrinter.printBarcode('01234567890', 8, 80, 2, 0);printQrCode()
printQrCode(data: string, moduleSize: number, errorLevel: number) : Promise<null>
Print QR Code (Two-Dimensional Barcode)
Parameters
- data : QR Code content data
- moduleSize : QR Code block size in Point (1 - 16)
- errorLevel : QR Code error correction Level (0 - 3)
- 0 = Error correction level L (7%)
- 1 = Error correction level M (15%)
- 2 = Error correction level Q (25%)
- 3 = Error correction level H (30%)
Examples
await SunmiPrinter.printQrCode('https://google.com', 8, 2);printBitmap()
printBitmap(data: string, width: number, height: number) : Promise<null>
Print Bitmap from Base-64 data
Parameters
- data : Base-64 bitmap data (Maximum width of 384 pixels)
- width
- height
Examples
const base64Image = '/9j/2wCEAAEBAQEBAQEBA...BKJzETKAj2KAAH//2Q==';
await SunmiPrinter.printBitmap(base64Image, 320, 80);Notes
If you want to print local image from device storage, you can use library like rn-fetch-blob or react-native-fs to convert the image to base64
openCashBox()
openCashBox() : Promise<null>
Open the Cash Box. If there is no Cash Box Interface (such as V1, P1) or the call fails, an exception will be thrown
Examples
await SunmiPrinter.openCashBox();Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT
Made with create-react-native-library
