0.0.3 • Published 2 years ago

nuri-sunmi-qr-printer v0.0.3

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

nuri-sunmi-qr-printer

Sunmi QR Code Scan & Printer

Install

npm install nuri-sunmi-qr-printer
npx cap sync

Android Only Setting

This API requires the following permissions be added to your AndroidManifest.xml before the application tag:

<!-- To get access to the camera. -->
<uses-permission android:name="android.permission.CAMERA" />
<!-- To get access to the flashlight. -->
<uses-permission android:name="android.permission.FLASHLIGHT"/>
AndroidManifest.xml

 <application
        android:name=".GlobalApplication" ">
        <activity
        </activity>
    </application>
//////////////////

import com.nuri.sunmi.qrprinter.SunmiQrPrinterPlugin;

public class GlobalApplication extends Application {

  String TAG = "GlobalApplication GlobalApplication";
  @Override
  public void onCreate() {
    super.onCreate();
    SunmiQrPrinterPlugin.Sunmi_Init(this);

    Log.v(TAG, "onCreate" );
  }

}

Usage

import { SunmiQrPrinter } from 'nuri-sunmi-qr-printer';


// QR Code Scan
  ngOnInit() {
    SunmiQrPrinter.addListener('Event_QRCodeData', (info: any) => {
        console.log('Event_QRCodeData : ', info.value);
    });
  }


	await SunmiQrPrinter.QR_Scan(data).then(res => {
      console.log('qrCode_data : ', res.value);
  });

// Sunmi Printer

  SunmiQrPrinter.Sunmi_GetIsConnnected()
    .then((result) => {
      console.log(" result.isConnnected : ", result.isConnnected);
    })
    .catch((err) => {
  });

  SunmiQrPrinter.Sunmi_GetPrinterStatus()
    .then((result) => {
      console.log(" result.isConnnected : ", result.printstats);


    })
    .catch((err) => {
  });

// QR Code ImgData ( Base64Image )  ====> this.qrCodeData
  getBase64StringFromDataURL(dataURL: string): string {

    dataURL = dataURL.replace('data:', '').replace(/^.+,/, '');

    return dataURL;
  }

  var qrCodeImgData = getBase64StringFromDataURL(....ImageData );

  var imageQrCode = {
    imgData: qrCodeImgData,
    nCanvasWidth: 384,
    nCanvasHeight: 200,
    nPosX: 0,
    nPosY: 0,
    nScaleWidth: 384,
    nScaleHeight: 200,
    nAlignment: 2,    // Center
  }
  SunmiQrPrinter.Sunmi_PrintBitmap(imageQrCode);

  // Left Aligin
  var text_round = {
    szFontName: "./assets/fonts/JetBrainsMono.ttf",
    msgText: round + '\n',
    fFontSize: 24,
    isBold: true,
    isUnderLine: false,
  }
  SunmiQrPrinter.Sunmi_PrintTextFont(text_round);
    //--------------------- Left Aligin

  // Right Aligin
  var text_Align = {
    nAlign: 2,
  }
  SunmiQrPrinter.Sunmi_SetAlign(text_Align);

  var text_TicketNo = {
    szFontName: "./assets/fonts/JetBrainsMono.ttf",
    msgText: TicketNo + '\n',
    fFontSize: 24,
    isBold: true,
    isUnderLine: false,
  }
  SunmiQrPrinter.Sunmi_PrintTextFont(text_TicketNo);
  //--------------------- Right Aligin


  var text_Msg = {
    msgText: '--------------------------------\n',
  }
  SunmiQrPrinter.Sunmi_PrintText(text_Msg);

  // Line Gap
  var text_Line = {
    nLine: 1,
  }
  SunmiQrPrinter.Sunmi_PrintLine(text_Line);


  SunmiQrPrinter.Sunmi_FeedPaper();

API

echo(...)

echo(options: { value: string; }) => Promise<{ value: string; }>
ParamType
options{ value: string; }

Returns: Promise<{ value: string; }>


addListener('Event_QRCodeData', ...)

addListener(eventName: 'Event_QRCodeData', listenerFunc: any) => Promise<PluginListenerHandle> & PluginListenerHandle
ParamType
eventName'Event_QRCodeData'
listenerFuncany

Returns: Promise<PluginListenerHandle> & PluginListenerHandle


QR_Scan(...)

QR_Scan(options: { value: string; }) => Promise<{ value: string; }>

Sunmi Qr Scan

ParamType
options{ value: string; }

Returns: Promise<{ value: string; }>


Sunmi_GetPrinterStatus()

Sunmi_GetPrinterStatus() => Promise<{ printstats: string; }>

Current status of printer

Returns: Promise<{ printstats: string; }>


Sunmi_GetIsConnnected()

Sunmi_GetIsConnnected() => Promise<{ isConnnected: string; }>

Check if the printer is connected

Returns: Promise<{ isConnnected: string; }>


Sunmi_PrintBitmap(...)

Sunmi_PrintBitmap(options: QR_Image_Print) => Promise<{ value: string; }>

Print pictures and text in the specified orde After the picture is printed, the line feed output needs to be called, otherwise it will be saved in the cache In this example, the image will be printed because the print text content is added

ParamType
optionsQR_Image_Print

Returns: Promise<{ value: string; }>


Sunmi_PrintText(...)

Sunmi_PrintText(options: Sunmi_PrintText) => Promise<{ value: string; }>

print text Set printer alignment ==> Sunmi_SetAlign 0 : Left, 1 : Center, 2 : Right

ParamType
optionsSunmi_PrintText

Returns: Promise<{ value: string; }>


Sunmi_PrintTextFont(...)

Sunmi_PrintTextFont(options: Sunmi_PrintText_Font) => Promise<{ value: string; }>

print text You can put the custom font in the 'assets' directory and Specify the font name parameters Set printer alignment ==> Sunmi_SetAlign 0 : Left, 1 : Center, 2 : Right

ParamType
optionsSunmi_PrintText_Font

Returns: Promise<{ value: string; }>


Sunmi_PrintLine(...)

Sunmi_PrintLine(options: Sunmi_Print_Line) => Promise<{ value: string; }>

paper feed three lines Not disabled when line spacing is set to 0 max line 3

ParamType
optionsSunmi_Print_Line

Returns: Promise<{ value: string; }>


Sunmi_SetAlign(...)

Sunmi_SetAlign(options: Sunmi_Text_Align) => Promise<{ value: string; }>

Set printer alignment 0 : Left, 1 : Center, 2 : Right

ParamType
optionsSunmi_Text_Align

Returns: Promise<{ value: string; }>


Sunmi_FeedPaper()

Sunmi_FeedPaper() => Promise<{ value: string; }>

Due to the distance between the paper hatch and the print head, the paper needs to be fed out automatically But if the Api does not support it, it will be replaced by printing three lines

Returns: Promise<{ value: string; }>


Interfaces

PluginListenerHandle

PropType
remove() => Promise<void>

QR_Image_Print

PropTypeDescription
imgDatastringImage Data Base64String
nCanvasWidthnumberCanvas Width size should be greater than or equal to the actual image size. ( CanvasWidth >= ImageWidth ) ( 캔버스 너비 크기는 실제 이미지 크기 이상이어야 합니다. (CanvasWidth >= ImageWidth ) )
nCanvasHeightnumberCanvas Height size should be greater than or equal to the actual image size. ( CanvasHeight >= ImageHeight ) ( 캔버스 높이 크기는 실제 이미지 크기보다 크거나 같아야 합니다. (CanvasHight >= ImageHeight ) )
nPosXnumberCanvas coordinates that allow you to print real images at the coordinates you want ( X (left) Point) 원하는 좌표로 실제 이미지를 출력할 수 있는 캔버스 좌표
nPosYnumberCanvas coordinates that allow you to print real images at the coordinates you want ( Y (top) Point) 원하는 좌표로 실제 이미지를 출력할 수 있는 캔버스 좌표
nScaleWidthnumberZoom flag The Scale Width shall not exceed a maximum of 384px. ( 0 ~ 384px ) ( 스케일 폭은 최대 384px를 초과해서는 안 됩니다. ) If it is smaller than 384px, the canvas image size is reduced. ( 384px보다 작으면 캔버스 이미지 크기가 줄어듭니다. )
nScaleHeightnumberZoom flag Scale height must be greater than 0px (resize desired) ( 스케일 높이는 0px보다 커야 합니다(원하는 크기 조정) )
nAlignmentnumberAlignment of actual image output positions 0 : default ==> nPosX, nPosY Point mark 1 : Left Align 2 : Center Align 3 : Right Align

Sunmi_PrintText

PropTypeDescription
msgTextstringText to print.

Sunmi_PrintText_Font

PropTypeDescription
szFontNamestringFont name definition
msgTextstringText to print.
fFontSizenumberFont Size
isBoldbooleanbold text
isUnderLinebooleanUnderline text

Sunmi_Print_Line

PropTypeDescription
nLinenumberpaper feed three lines Not disabled when line spacing is set to 0 max line 3

Sunmi_Text_Align

PropTypeDescription
nAlignnumberSet printer alignment 0 : Left, 1 : Center, 2 : Right
0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago