0% found this document useful (0 votes)
324 views3 pages

Sunmi Inner Printer Plugin Guide

The document discusses using a Sunmi inner printer plugin for Cordova. It includes code snippets for installing the plugin, initializing and calling printing methods on the printer. It also discusses issues encountered and solutions for printing synchronously vs asynchronously in a Cordova app.

Uploaded by

Jose Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
324 views3 pages

Sunmi Inner Printer Plugin Guide

The document discusses using a Sunmi inner printer plugin for Cordova. It includes code snippets for installing the plugin, initializing and calling printing methods on the printer. It also discusses issues encountered and solutions for printing synchronously vs asynchronously in a Cordova app.

Uploaded by

Jose Santos
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

sunmiInnerPrinter.

printTextWithFont('\nABC Computers ','Calibri',36);


sunmiInnerPrinter.printTextWithFont('\nPlot No. 2, Road No 7, \nBanjara Hills,
\Hyderabad, 500003, TG \nPhone: +91 9876543210','Calibri',24);
sunmiInnerPrinter.printTextWithFont('\n**************************','Calibri',24);
sunmiInnerPrinter.printTextWithFont('\nName: Sachin\n','Calibri',32);
sunmiInnerPrinter.printTextWithFont('\nPhone: 9988776655\n','Calibri',32);
sunmiInnerPrinter.printTextWithFont('\nEmail: test@test.com\n','Calibri',32);

window.sunmiInnerPrinter.printerInit();
window.sunmiInnerPrinter.printerSelfChecking();
window.sunmiInnerPrinter.printOriginalText("Hello World!");
window.sunmiInnerPrinter.printString("Hello World!");

ionic cordova platform add android@6.3.0

(<any>window).plugins.sunmiInnerPrinter.printString("Hello String!");

i found a new plugin created by labibramadhan. Thanks labib

you can find the plugin here

https://github.com/labibramadhan/cordova-sunmi-inner-printer

First, install by typing ionic

cordova plugin add https://github.com/labibramadhan/cordova-sunmi-inner-printer.git

Then, use it on your cordova javascript codes by calling:

window.sunmiInnerPrinter.printOriginalText("Hello World!")

window.sunmiInnerPrinter.[methods available on here]

https://github.com/labibramadhan/cordova-sunmi-inner-
printer/blob/master/www/innerprinter.js

Thank you

For Ionic 3: In .ts file, add "declare let sunmiInnerPrinter: any;" before
@Component and call the methods as "sunmiInnerPrinter.printOriginalText("Hello
Printer");"

@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 C:/compo/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
}

https://github.com/labibramadhan/cordova-sunmi-inner-printer/issues/14

toPrintOrder(){
var lines = ["产品","数量","单价"];
var widths = [16,4,6,];
var aligns = [0,1,2];
var address = this.state.order.address;
var orderNumber = this.state.order.orderNumber;
if(orderNumber){
orderNumber = orderNumber.replace('OTN_','');
}
SunmiInnerPrinter.printString("牛家作订单: "+ dateFormat(new Date(),'yyyy-
MM-dd HH:mm:ss')
+"\n 地址:\n"

+"--"+address.province+address.city+address.district+address.street+address.address
+"\n"
+"联系方式:\n"
+"--"+address.contact+"\n\n")

.then(()=>SunmiInnerPrinter.printString("================================\n"))
.then(()=>SunmiInnerPrinter.printColumnsText(lines,widths,aligns))
.then(()=>{
for(var i=0;i<this.state.order.products.length;i++){
var p = this.state.order.products[i];
var lines = [p.name,p.quantity+"",p.price+""]
SunmiInnerPrinter.printColumnsText(lines,widths,aligns)

if(i== this.state.order.products.length-1){
//set timeout to make sure print completed.
setTimeout(()=> {
return
SunmiInnerPrinter.printString("================================\n")

.then(()=>SunmiInnerPrinter.printString("共"+this.state.order.products.length+"件,共
计:"+this.state.order.bill.total+"元\n"))

.then(()=>SunmiInnerPrinter.printBarCode(orderNumber,8,80,2,2))
.then(()=>SunmiInnerPrinter.printString("\n\n\n\n"))
.then(()=>{
SunmiInnerPrinter.commitPrinterBuffer();// actually no
need to commit.
Alert.alert("打印完成","打印完成");
});
},200);
}
}
}).catch((err)=>{
Alert.alert("打印出错","打印出错");
});

esto está sucediendo porque es sincrónica. simplemente esperar a que cada promesa
de resolver antes de pasar a la siguiente. Esto debería funcionar.

sunmiInnerPrinter.printTextWithFont('\nABC Computers ','Calibri',36).then((f: any)


=> {
sunmiInnerPrinter.printTextWithFont('\nPlot No. 2, Road No 7, \nBanjara Hills,
\Hyderabad, 500003, TG \nPhone: +91 9876543210','Calibri',24).then(
...etc.
)
})

You might also like