React Native Library for SUNMI Inner Printer (Android only)
npm install @hendrysetiadi/react-native-sunmi-printerimport SunmiPrinter from '@hendrysetiadi/react-native-sunmi-printer';
// or ES6+ destructured imports
import { initPrinter } from '@hendrysetiadi/react-native-sunmi-printer';getPrinterSerialNo(): Promise<string>
const serialNo = await SunmiPrinter.getPrinterSerialNo();getPrinterModel(): Promise<string>
const printerModel = await SunmiPrinter.getPrinterModel();getPrinterVersion(): Promise<string>
const printerVersion = await SunmiPrinter.getPrinterVersion();getPrinterPaper(): Promise<string>
const printerPaper = await SunmiPrinter.getPrinterPaper();initPrinter(): Promise<null>
Initialize printer and reset printer state (font size, alignment, etc.), should be called first before the print call
await SunmiPrinter.getPrinterPaper();printLineWrap(n: number) : Promise<null>
Print Paper Feed after finishing the Previous printing content
- n : Number of Lines
await SunmiPrinter.printLineWrap(3);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
await SunmiPrinter.feedPaper();setAlignment(alignment: number) : Promise<null>
Set the Printing Alignment (Setting the printing alignment will affect subsequent printing unless it is initialized)
- alignment : Alignment Mode (0 = Left, 1 = Center, 2 = Right)
// Set Alignment to Center
await SunmiPrinter.setAlignment(1);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
await SunmiPrinter.setFontSize(32);printText(content: string) : Promise<null>
- content : Text to Print
await SunmiPrinter.printText('Hello World');printTextWithOption(content: string, fontSize: number, isBold: boolean, isUnderline: boolean) : Promise<null>
Print Text with Size, Bold, and Underline options
- content : Text to Print
- fontSize
- isBold
- isUnderline
await SunmiPrinter.printTextWithOption('Hello World', 24, true, true);printTextTable(contentArray: string[], widthArray: number[], alignmentArray: number[]) : Promise<null>
Print Text in a form of Table (can specify the column Width and Alignment)
- 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)
await SunmiPrinter.printTextTable(
['Date', 'Jan 1st, 10:00 AM'],
[1, 1],
[0, 2]
);printBarcode(data: string, symbology: number, height: number, width: number, textPosition: number) : Promise<null>
Print One-Dimensional Barcode
- 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
await SunmiPrinter.printBarcode('01234567890', 8, 80, 2, 0);printQrCode(data: string, moduleSize: number, errorLevel: number) : Promise<null>
Print QR Code (Two-Dimensional Barcode)
- 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%)
await SunmiPrinter.printQrCode('https://google.com', 8, 2);printBitmap(data: string, width: number, height: number) : Promise<null>
Print Bitmap from Base-64 data
- data : Base-64 bitmap data (Maximum width of 384 pixels)
- width
- height
const base64Image = '/9j/2wCEAAEBAQEBAQEBA...BKJzETKAj2KAAH//2Q==';
await SunmiPrinter.printBitmap(base64Image, 320, 80);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() : 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
await SunmiPrinter.openCashBox();See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT
Made with create-react-native-library