cordova-sunmi-inner-printer
cordova-sunmi-inner-printer copied to clipboard
cordova - sunmi-inner-printer
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,
- you need to declare the variables before any class declaration as follows:
declare var sunmiInnerPrinter: any;
-
you need to use the "sunmiInnerPrinter" after ionViewDidLoad()
-
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)); }
- you need to declare the variables before any class declaration as follows:
declare var sunmiInnerPrinter: any;
- you need to use the "sunmiInnerPrinter" after ionViewDidLoad()
- 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));
}
// (
- make sure you have the cordova-plugin-sunmi-inner-printer
- please do the ff: cd to your project dir and type "cordova plugin list"
- make sure you have the cordova-plugin-sunmi-inner-printer
- 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
I remember I have the same problem, then I did modify this plugin. I will post the modify version asap
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
try this one https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer
@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"
- 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 }
@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"
- 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
@gayu1712
-
convert your html page into bitmap, see https://stackoverflow.com/questions/21214620/render-html-text-to-bitmap-using-javascript-without-serverside-code
-
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) );
@gayu1712
- convert your html page into bitmap, see https://stackoverflow.com/questions/21214620/render-html-text-to-bitmap-using-javascript-without-serverside-code
- 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
@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.
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
@gayu1712 You need to convert the stackoverflow code into typescript form to use it
@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.
@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.
@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
@gayu1712 I am sorry. I can't do that. It was already own by my client ;-)
@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
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 If i use this "export class HtmlToBitmap extends CanvasRenderingContext2D" , i got illegal constructor error even i use super(); also i got the same error
@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
@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 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
found solution with this thread, thanks @tmalbonph
found solution with this thread, thanks @tmalbonph
Your welcome @gItSpLasHeR
found solution with this thread, thanks @tmalbonph
Hi, Did u find that in ionic3 , to print html page with api calling.
@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
@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 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