nuri-sunmi-qr-printer
v0.0.3
Published
Sunmi QR Code Scan & Printer
Downloads
1
Readme
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(...)
addListener('Event_QRCodeData', ...)
QR_Scan(...)
Sunmi_GetPrinterStatus()
Sunmi_GetIsConnnected()
Sunmi_PrintBitmap(...)
Sunmi_PrintText(...)
Sunmi_PrintTextFont(...)
Sunmi_PrintLine(...)
Sunmi_SetAlign(...)
Sunmi_FeedPaper()
- Interfaces
echo(...)
echo(options: { value: string; }) => Promise<{ value: string; }>
| Param | Type |
| ------------- | ------------------------------- |
| options
| { value: string; } |
Returns: Promise<{ value: string; }>
addListener('Event_QRCodeData', ...)
addListener(eventName: 'Event_QRCodeData', listenerFunc: any) => Promise<PluginListenerHandle> & PluginListenerHandle
| Param | Type |
| ------------------ | ------------------------------- |
| eventName
| 'Event_QRCodeData' |
| listenerFunc
| any |
Returns: Promise<PluginListenerHandle> & PluginListenerHandle
QR_Scan(...)
QR_Scan(options: { value: string; }) => Promise<{ value: string; }>
Sunmi Qr Scan
| Param | Type |
| ------------- | ------------------------------- |
| 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
| Param | Type |
| ------------- | --------------------------------------------------------- |
| options
| QR_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
| Param | Type |
| ------------- | ----------------------------------------------------------- |
| options
| Sunmi_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
| Param | Type |
| ------------- | --------------------------------------------------------------------- |
| options
| Sunmi_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
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| options
| Sunmi_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
| Param | Type |
| ------------- | ------------------------------------------------------------- |
| options
| Sunmi_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
| Prop | Type |
| ------------ | ----------------------------------------- |
| remove
| () => Promise<void> |
QR_Image_Print
| Prop | Type | Description |
| ------------------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| imgData
| string | Image Data Base64String |
| nCanvasWidth
| number | Canvas Width size should be greater than or equal to the actual image size. ( CanvasWidth >= ImageWidth ) ( 캔버스 너비 크기는 실제 이미지 크기 이상이어야 합니다. (CanvasWidth >= ImageWidth ) ) |
| nCanvasHeight
| number | Canvas Height size should be greater than or equal to the actual image size. ( CanvasHeight >= ImageHeight ) ( 캔버스 높이 크기는 실제 이미지 크기보다 크거나 같아야 합니다. (CanvasHight >= ImageHeight ) ) |
| nPosX
| number | Canvas coordinates that allow you to print real images at the coordinates you want ( X (left) Point) 원하는 좌표로 실제 이미지를 출력할 수 있는 캔버스 좌표 |
| nPosY
| number | Canvas coordinates that allow you to print real images at the coordinates you want ( Y (top) Point) 원하는 좌표로 실제 이미지를 출력할 수 있는 캔버스 좌표 |
| nScaleWidth
| number | Zoom 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보다 작으면 캔버스 이미지 크기가 줄어듭니다. ) |
| nScaleHeight
| number | Zoom flag Scale height must be greater than 0px (resize desired) ( 스케일 높이는 0px보다 커야 합니다(원하는 크기 조정) ) |
| nAlignment
| number | Alignment of actual image output positions 0 : default ==> nPosX, nPosY Point mark 1 : Left Align 2 : Center Align 3 : Right Align |
Sunmi_PrintText
| Prop | Type | Description |
| ------------- | ------------------- | -------------- |
| msgText
| string | Text to print. |
Sunmi_PrintText_Font
| Prop | Type | Description |
| ----------------- | -------------------- | -------------------- |
| szFontName
| string | Font name definition |
| msgText
| string | Text to print. |
| fFontSize
| number | Font Size |
| isBold
| boolean | bold text |
| isUnderLine
| boolean | Underline text |
Sunmi_Print_Line
| Prop | Type | Description |
| ----------- | ------------------- | ---------------------------------------------------------------------------- |
| nLine
| number | paper feed three lines Not disabled when line spacing is set to 0 max line 3 |
Sunmi_Text_Align
| Prop | Type | Description |
| ------------ | ------------------- | ----------------------------------------------------- |
| nAlign
| number | Set printer alignment 0 : Left, 1 : Center, 2 : Right |