labibramadhan / cordova-sunmi-inner-printer

29 stars 32 forks source link

cordova - sunmi-inner-printer #14

Open gayathri-17 opened 6 years ago

gayathri-17 commented 6 years ago

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 android@6.3.0, 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,

tmalbonph commented 6 years ago
  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)); }

gayathri-17 commented 6 years ago
  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

tmalbonph commented 6 years ago
  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"
gayathri-17 commented 6 years ago
  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

tmalbonph commented 6 years ago

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

gayathri-17 commented 6 years ago

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

tmalbonph commented 6 years ago

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

tmalbonph commented 6 years ago

@gayu1712

1. cd PATH/TO/NEW/SUNMI/PRINTER git clone git@github.com@tmalbonph:cordova-plugin-sunmi-inner-printer.git

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

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

4. 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 }

gayathri-17 commented 6 years ago

@gayu1712

cd PATH/TO/NEW/SUNMI/PRINTER git clone git@github.com@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

tmalbonph commented 6 years ago

@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) );

gayathri-17 commented 6 years ago

@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

tmalbonph commented 6 years ago

@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.

gayathri-17 commented 6 years ago

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

tmalbonph commented 6 years ago

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

gayathri-17 commented 6 years ago

@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.

tmalbonph commented 6 years ago

@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.

gayathri-17 commented 6 years ago

@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 commented 6 years ago

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

gayathri-17 commented 6 years ago

@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

tmalbonph commented 6 years ago

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) {
...
}

}

gayathri-17 commented 6 years ago

@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 commented 6 years ago

@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

tmalbonph commented 6 years ago

@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 commented 6 years ago

@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

gIt-SpLasHeR commented 6 years ago

found solution with this thread, thanks @tmalbonph

tmalbonph commented 6 years ago

found solution with this thread, thanks @tmalbonph

Your welcome @gItSpLasHeR

gayathri-17 commented 6 years ago

found solution with this thread, thanks @tmalbonph

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

gayathri-17 commented 6 years ago

@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 commented 6 years ago

@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?

gayathri-17 commented 6 years ago

@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

tmalbonph commented 6 years ago

@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 still getting same error , i dono how to print that html page

@gayu1712 I am sorry; I have limited time this month to help.

saberprashant commented 5 years ago

Hi @tmalbonph , can you please help me with this. I am trying to make this plugin work with ionic1 app. When I tried with ionic3, it worked perfectly, but for ionic1, I am getting errors. Please help.

tmalbonph commented 5 years ago

Hi @tmalbonph , can you please help me with this. I am trying to make this plugin work with ionic1 app. When I tried with ionic3, it worked perfectly, but for ionic1, I am getting errors. Please help.

Hi @saberprashant Can you post the error here.

saberprashant commented 5 years ago

@tmalbonph , It is showing this error:

Failed to load resource: net::ERR_FILE_NOT_FOUND     (in innerprinter.js)

I am integrating like this:

tmalbonph commented 5 years ago

@saberprashant

export PPWD=`pwd`

sudo mkdir -p /driver
sudo chown $USER:$USER /driver
sudo chmod 0700 /driver
cd /driver
git clone git@github.com:tmalbonph/cordova-plugin-sunmi-inner-printer.git

cd $PPWD/
gedit package.json
    "cordova-android": "^6.3.0",
    "cordova-plugin-sunmi-inner-printer": "file:/driver/cordova-plugin-sunmi-inner-printer",
    "jquery": "^3.2.1",
saberprashant commented 5 years ago

@tmalbonph , I followed everything and I am getting this error on running 2nd last command -> cd $PPWD/

bash: cd: pwd/: No such file or directory
tmalbonph commented 5 years ago

@saberprashant I am guessing that you have problem with pwd. You can do the following instead.

export PPWD=/PATH/TO/WHERE/YOUR/package.json

sudo mkdir -p /driver
sudo chown $USER:$USER /driver
sudo chmod 0700 /driver
cd /driver
git clone git@github.com:tmalbonph/cordova-plugin-sunmi-inner-printer.git

cd $PPWD/
gedit package.json
{
    "cordova-android": "^6.3.0",
    "cordova-plugin-sunmi-inner-printer": "file:/driver/cordova-plugin-sunmi-inner-printer",
    "jquery": "^3.2.1",
}

Let me know if it works for you.

tmalbonph commented 5 years ago

@saberprashant

{
    "cordova-plugin-sunmi-inner-printer": "file:/driver/cordova-plugin-sunmi-inner-printer",
}
saberprashant commented 5 years ago

Hi @tmalbonph , thank you so much for your help. It worked with your repo. 🍻

tmalbonph commented 5 years ago

Hi @tmalbonph , thank you so much for your help. It worked with your repo.

@saberprashant I am glad the changes I had made with "cordova-sunmi-inner-printer" help your "SUNMI" project.

ma851tos commented 5 years ago
  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 i'm trying to use your plugin, after installing it in ionic 4 followed these steps but i still get that sunmiInnerPrinter is undefined i tried in every way possible but still doesn't work how do i fix that..?

tmalbonph commented 5 years ago

@tmalbonph i'm trying to use your plugin, after installing it in ionic 4 followed these steps but i still get that sunmiInnerPrinter is undefined i tried in every way possible but still doesn't work how do i fix that..?

@ma851tos

  1. If you want further help from me, please do the following:

  2. Create an issue here cordova-plugin-sunmi-inner-printer

  3. Create a question in Stack Overflow and mention the github issue you created in step 2.

  4. Make sure you tag your "stackoverflow question" with android, android-gradle, ionic3, and ionic4 tags.

  5. Finally, post the link of the "stackoverflow question" you have created in step 4, so I can properly response on it.

ma851tos commented 5 years ago

@tmalbonph i'm trying to use your plugin, after installing it in ionic 4 followed these steps but i still get that sunmiInnerPrinter is undefined i tried in every way possible but still doesn't work how do i fix that..?

@ma851tos

  1. If you want further help from me, please do the following:
  2. Create an issue here cordova-plugin-sunmi-inner-printer
  3. Create a question in Stack Overflow and mention the github issue you created in step 2.
  4. Make sure you tag your "stackoverflow question" with android, android-gradle, ionic3, and ionic4 tags.
  5. Finally, post the link of the "stackoverflow question" you have created in step 4, so I can properly response on it.

thank you for you answer

i did it

https://stackoverflow.com/questions/56473958/use-sunmi-inner-printer-in-ionic

saravanacs commented 5 years ago

Please anyone help me, Using Cordova sunmi printer is working fine. But, i need Printer status before printing. Example, Validate printer status, Don't allow to do printer is not available and not ready or paper not available.

Thanks in Advance

tmalbonph commented 5 years ago

Please anyone help me, Using Cordova sunmi printer is working fine. But, i need Printer status before printing. Example, Validate printer status, Don't allow to do printer is not available and not ready or paper not available.

Thanks in Advance

@saberprashant Please post your issue here: https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer/issues

saravanacs commented 5 years ago

Please anyone help me, Using Cordova sunmi printer is working fine. But, i need Printer status before printing. Example, Validate printer status, Don't allow to do printer is not available and not ready or paper not available. Thanks in Advance

@saberprashant Please post your issue here: https://github.com/tmalbonph/cordova-plugin-sunmi-inner-printer/issues

Okay sir, Please help me to solve sunmi printer validation

saravanacs commented 5 years ago

what is the use of printerStatusStartListener(); and what value is return ?

lunadeistanbul7 commented 4 years ago

@tmalbonph I want to integrate pos bluetooth printer for merchant app Sunmi Can you help me please?

lunadeistanbul7 commented 4 years ago

@tmalbonph I want to integrate pos bluetooth printer for merchant app Sunmi

tmalbonph commented 4 years ago

@lunadeistanbul7 What kind of help do you want from me?