cordova-sunmi-inner-printer icon indicating copy to clipboard operation
cordova-sunmi-inner-printer copied to clipboard

cordova - sunmi-inner-printer

Open gayathri-17 opened this issue 6 years ago • 53 comments

Hi Sir, I am using ionic3 app, for that i am using sunmi pos , i want to print a receipt , i installed the plugin successfully in [email protected], after that i declare let sunmiInnerPrinter: any; before @component in that particular .ts page and i call as " sunmiInnerPrinter.printOriginalText("Hello Printer"); " , i got error as "Uncaught (in promise): ReferenceError: sunmiInnerPrinter is not defined" can u pls explain how can i clear this issue ASAP, thank you,

gayathri-17 avatar Oct 16 '18 07:10 gayathri-17

  1. you need to declare the variables before any class declaration as follows:

declare var sunmiInnerPrinter: any;

  1. you need to use the "sunmiInnerPrinter" after ionViewDidLoad()

  2. if you want to see the error on using the "sunmiInnerPrinter", you enclose your code inside the try - catch block.

try { if (JSON.stringify(sunmiInnerPrinter) !== "{}") { return; } // it is safe to use sunmiInnerPrinter here } catch(err) { console.log("error: "+ JSON.stringify(err)); }

tmalbonph avatar Oct 16 '18 07:10 tmalbonph

  1. you need to declare the variables before any class declaration as follows:

declare var sunmiInnerPrinter: any;

  1. you need to use the "sunmiInnerPrinter" after ionViewDidLoad()
  2. if you want to see the error on using the "sunmiInnerPrinter", you enclose your code inside the try - catch block.

try { if (JSON.stringify(sunmiInnerPrinter) !== "{}") { return; } // it is safe to use sunmiInnerPrinter here } catch(err) { console.log("error: "+ JSON.stringify(err)); }

//// Hi sir , i did that, but i got same error , import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular';

declare var sunmiInnerPrinter: any; @IonicPage() @Component({ selector: 'page-receipt', templateUrl: 'receipt.html', }) export class ReceiptPage {

constructor(public navCtrl: NavController, public navParams: NavParams) { this.print(); }

ionViewDidLoad() { console.log('ionViewDidLoad ReceiptPage'); } print(){ try { if (JSON.stringify(sunmiInnerPrinter) !== "{}") { return; } // it is safe to use sunmiInnerPrinter here } catch(err) { console.log("error: "+ JSON.stringify(err)); } // (window).plugins.sunmiInnerPrinter.printOriginalText("Hello Printer"); // (window).plugins.sunmiInnerPrinter.printString("Hello String!"); // sunmiInnerPrinter.printOriginalText("Hello Printer"); } } and i get -- error: {}, only and iam using sunmi-machine - model POS-V1, can u pls help me

gayathri-17 avatar Oct 16 '18 08:10 gayathri-17

  1. make sure you have the cordova-plugin-sunmi-inner-printer
  2. please do the ff: cd to your project dir and type "cordova plugin list"

tmalbonph avatar Oct 16 '18 08:10 tmalbonph

  1. make sure you have the cordova-plugin-sunmi-inner-printer
  2. please do the ff: cd to your project dir and type "cordova plugin list"

ya i am having sir, cordova-plugin-device 2.0.2 "Device" cordova-plugin-inappbrowser 3.0.0 "InAppBrowser" cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 2.2.0 "cordova-plugin-ionic-webview" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist" cordova-sunmi-inner-printer 1.0.0 "SunmiInnerPrinter" phonegap-plugin-barcodescanner 8.0.0 "BarcodeScanner" is there i want to import in app.module.ts file

gayathri-17 avatar Oct 16 '18 08:10 gayathri-17

I remember I have the same problem, then I did modify this plugin. I will post the modify version asap

tmalbonph avatar Oct 16 '18 08:10 tmalbonph

I remember I have the same problem, then I did modify this plugin. I will post the modify version asap

Tq sir, pls post asap

gayathri-17 avatar Oct 16 '18 08:10 gayathri-17

try this one https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer

tmalbonph avatar Oct 16 '18 10:10 tmalbonph

@gayu1712

cd PATH/TO/NEW/SUNMI/PRINTER git clone [email protected]@tmalbonph:cordova-plugin-sunmi-inner-printer.git

cd PATH/OF/YOUR/IONIC/PROJECT ionic cordova plugin rm cordova-plugin-sunmi-inner-printer

ionic cordova plugin add PATH/TO/NEW/SUNMI/PRINTER/cordova-plugin-sunmi-inner-printer --nofetch

cordova plugin list

cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-console 1.1.0 "Console" cordova-plugin-device 1.1.7 "Device" cordova-plugin-inappbrowser 1.7.2 "InAppBrowser" cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview" cordova-plugin-native-spinner 1.1.3 "Native Spinner" cordova-plugin-splashscreen 4.1.0 "Splashscreen" cordova-plugin-statusbar 2.4.1 "StatusBar" cordova-plugin-sunmi-inner-printer 1.1.0 "SunmiInnerPrinter" cordova-plugin-whitelist 1.3.3 "Whitelist" es6-promise-plugin 4.2.2 "Promise" ionic-plugin-deeplinks 1.0.15 "Ionic Deeplink Plugin" ionic-plugin-keyboard 2.2.1 "Keyboard"

  1. edit PATH/OF/YOUR/IONIC/PROJECT/platforms/android/build.gradle

dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile "com.sunmi:sunmiui:latest.release" <------ ADD THIS // SUB-PROJECT DEPENDENCIES START debugCompile(project(path: "CordovaLib", configuration: "debug")) releaseCompile(project(path: "CordovaLib", configuration: "release")) // SUB-PROJECT DEPENDENCIES END }

tmalbonph avatar Oct 16 '18 11:10 tmalbonph

@gayu1712

cd PATH/TO/NEW/SUNMI/PRINTER git clone [email protected]@tmalbonph:cordova-plugin-sunmi-inner-printer.git

cd PATH/OF/YOUR/IONIC/PROJECT ionic cordova plugin rm cordova-plugin-sunmi-inner-printer

ionic cordova plugin add PATH/TO/NEW/SUNMI/PRINTER/cordova-plugin-sunmi-inner-printer --nofetch

cordova plugin list

cordova-plugin-compat 1.2.0 "Compat" cordova-plugin-console 1.1.0 "Console" cordova-plugin-device 1.1.7 "Device" cordova-plugin-inappbrowser 1.7.2 "InAppBrowser" cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview" cordova-plugin-native-spinner 1.1.3 "Native Spinner" cordova-plugin-splashscreen 4.1.0 "Splashscreen" cordova-plugin-statusbar 2.4.1 "StatusBar" cordova-plugin-sunmi-inner-printer 1.1.0 "SunmiInnerPrinter" cordova-plugin-whitelist 1.3.3 "Whitelist" es6-promise-plugin 4.2.2 "Promise" ionic-plugin-deeplinks 1.0.15 "Ionic Deeplink Plugin" ionic-plugin-keyboard 2.2.1 "Keyboard"

  1. edit PATH/OF/YOUR/IONIC/PROJECT/platforms/android/build.gradle

dependencies { compile fileTree(dir: 'libs', include: '*.jar') compile "com.sunmi:sunmiui:latest.release" <------ ADD THIS // SUB-PROJECT DEPENDENCIES START debugCompile(project(path: "CordovaLib", configuration: "debug")) releaseCompile(project(path: "CordovaLib", configuration: "release")) // SUB-PROJECT DEPENDENCIES END }

Tq sir, Its working tq so much sir, in that "printOriginalText" i want to print one html page , how can i do that

gayathri-17 avatar Oct 16 '18 12:10 gayathri-17

@gayu1712

  1. convert your html page into bitmap, see https://stackoverflow.com/questions/21214620/render-html-text-to-bitmap-using-javascript-without-serverside-code

  2. use the following to print the bitmap image as follows:

sunmiInnerPrinter.printBitmap(YOUR_BITMAP, width, height, function(okay){ console.log('okay: '+ JSON.stringify(okay)); }.bind(this), function(error){ console.log('ERROR: '+ JSON.stringify(error)); }.bind(this) );

tmalbonph avatar Oct 16 '18 22:10 tmalbonph

@gayu1712

  1. convert your html page into bitmap, see https://stackoverflow.com/questions/21214620/render-html-text-to-bitmap-using-javascript-without-serverside-code
  2. use the following to print the bitmap image as follows:

sunmiInnerPrinter.printBitmap(YOUR_BITMAP, width, height, function(okay){ console.log('okay: '+ JSON.stringify(okay)); }.bind(this), function(error){ console.log('ERROR: '+ JSON.stringify(error)); }.bind(this) );

@tmalbonph Actually i want to bind a data from api after that i want to print that html page,is it possible in ionic3

gayathri-17 avatar Oct 17 '18 06:10 gayathri-17

@gayu1712 anything is possible. the printBitmap() only accept base64 string of a Window Bitmap image. You need to convert the sample code from here https://stackoverflow.com/questions/21214620/render-html-text-to-bitmap-using-javascript-without-serverside-code into a Windows Bitmap image.

tmalbonph avatar Oct 17 '18 06:10 tmalbonph

You need to convert the sample code from her

@tmalbonph I get an error in this line " ctx.drawHTMLText(...html here...);" as does not exist on type , i want to install anyting for that, or anyother solution is there

gayathri-17 avatar Oct 17 '18 07:10 gayathri-17

@gayu1712 You need to convert the stackoverflow code into typescript form to use it

tmalbonph avatar Oct 17 '18 07:10 tmalbonph

@gayu1712 You need to convert the stackoverflow code into typescript form to use it

@tmalbonph I can't get it, i try that but i dono how to do correctly, i want to print like a bill.

gayathri-17 avatar Oct 17 '18 08:10 gayathri-17

@gayu1712 On my latest project, I am using this modified plugin here https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer to print ticket for booking services and been using printBitmap() to print my client logo; using printOriginalText() to print ticket details; using printQRCode() to print the ticket reference number as QRCode and lineWrap(4) at the end of printing with no problem at all.

tmalbonph avatar Oct 17 '18 09:10 tmalbonph

@gayu1712 On my latest project, I am using this modified plugin here https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer to print ticket for booking services and been using printBitmap() to print my client logo; using printOriginalText() to print ticket details; using printQRCode() to print the ticket reference number as QRCode and lineWrap(4) at the end of printing with no problem at all.

@tmalbonph Can u post your reference code ..for How to do that

gayathri-17 avatar Oct 17 '18 11:10 gayathri-17

@gayu1712 I am sorry. I can't do that. It was already own by my client ;-)

tmalbonph avatar Oct 17 '18 11:10 tmalbonph

@gayu1712 I am sorry. I can't do that. It was already own by my client ;-)

@tmalbonph can u explain me how u change that code to .ts format

gayathri-17 avatar Oct 17 '18 11:10 gayathri-17

You can do something like:

save this as PATH/TO/YOUR/IONIC/PROJECT/src/app/htmltobitmap.module.ts

@Injectable() export class HtmlToBitmap extends CanvasRenderingContext2D {

public drawHTMLText(txt: string, options?: any) {
...
}

}

tmalbonph avatar Oct 17 '18 11:10 tmalbonph

@tmalbonph If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error

gayathri-17 avatar Oct 17 '18 14:10 gayathri-17

@gayu1712 On my latest project, I am using this modified plugin here https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer to print ticket for booking services and been using printBitmap() to print my client logo; using printOriginalText() to print ticket details; using printQRCode() to print the ticket reference number as QRCode and lineWrap(4) at the end of printing with no problem at all.

@tmalbonph Can u post your reference code ..for How to do that

@tmalbonph In above u said printOriginalText() to print ticket details; , how could you do that by using an html tag,can u elaborate

gayathri-17 avatar Oct 17 '18 15:10 gayathri-17

@gayu1712 printOriginalText() is for printing text. The text is normally 32 characters long per line. The line width is 58mm (the maximum width of your printer's thermal paper). The text can consist of single line or multiple lines separated by line feed (0x0A). Printing via printOriginalText() is faster compare to printBitmap() and I think it will help to extend the life of your printer thermal unit, beyond its "Printer service life" of 50km.

tmalbonph avatar Oct 17 '18 21:10 tmalbonph

@tmalbonph If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error

I don't get this error while I encoded it using Visual Studio Code version 1.27.2

tmalbonph avatar Oct 17 '18 21:10 tmalbonph

found solution with this thread, thanks @tmalbonph

gIt-SpLasHeR avatar Oct 25 '18 13:10 gIt-SpLasHeR

found solution with this thread, thanks @tmalbonph

Your welcome @gItSpLasHeR

tmalbonph avatar Oct 25 '18 13:10 tmalbonph

found solution with this thread, thanks @tmalbonph

Hi, Did u find that in ionic3 , to print html page with api calling.

gayathri-17 avatar Oct 29 '18 10:10 gayathri-17

@tmalbonph If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error

I don't get this error while I encoded it using Visual Studio Code version 1.27.2

HI , Still know i cant print my html page and the same time when i clone the project , cordova -sunmi printer is failed to install after that i have to install separately, then only its working

gayathri-17 avatar Oct 29 '18 10:10 gayathri-17

@tmalbonph If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error

I don't get this error while I encoded it using Visual Studio Code version 1.27.2

HI , Still i know i cant print my html page and the same time when i clone the project , cordova -sunmi printer is failed to install after that i have to install separately, then only its working

Hi @gayu1712 Do I need to fix every error you have?

tmalbonph avatar Oct 29 '18 10:10 tmalbonph

@tmalbonph If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error

I don't get this error while I encoded it using Visual Studio Code version 1.27.2

HI , Still i know i cant print my html page and the same time when i clone the project , cordova -sunmi printer is failed to install after that i have to install separately, then only its working

Hi @gayu1712 Do I need to fix every error you have?

Hi @tmalbonph i really need u r help, still getting same error , i dono how to print that html page

gayathri-17 avatar Oct 29 '18 11:10 gayathri-17