Closed lawrencehui closed 7 years ago
@lawrencehui plz check SunmiInnerPrinterModule.java that you can find those react methods asynchronous. for those method, you can call with then(). plz see some code like that (demo for a real project)
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("打印出错","打印出错");
});
}
Hi good day.. How do you align center in a new line of all the arrays on printColumnsText and also do you have examples on printing bitmap.. Thanks
Can u read Chinese? If u can, you can read the official document.
发自我的 iPhone
在 2017年5月10日,下午2:58,Roberto P. Gludo II notifications@github.com 写道:
Hi good day.. How do you align center in a new line of all the arrays on printColumnsText and also do you have examples on printing bitmap.. Thanks
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
Sorry I can't read Chinese..
@RobertStuff
Method setAligment can set the alignment model, effects until re-init the printer or call setAligment again.
var alignment = 0 // align left
alignment =1 // center
alignment = 2 // align right
SunmiInnerPrinter.setAlignment(alignment)
printColumnsText method with the agruments cloumnTextArray, ColumnWidthArray and columnAlign. columnAlign effects in the column which ordered by the array index, values would be:0-left, 1-center,2-right. Here a example that the first column aligns right, second aligns center, third aligns left
var widths = [12,6,6]
var aligns = [2,1,0];
var texts = ['l1-c1','l1-c2','l1-c3'];
SunmiInnerPrinter.printColumnsText(texts,widths,aligns);
texts = ['l2-c1','l2-c2','l2-c3'];
SunmiInnerPrinter.printColumnsText(texts,widths,aligns);
printBitmap method with arguments: data,width and height, max support width is 384 pix. argument "data" should be a base64 encode string.
I am thinking about the demos. however I still got no time for that. I would consider it when more and more user working on Sunmi products.
Yup.. thanks for your immediate reply. really appreciate... I loop to the array and put it in printString to align center..
@januslo May I know what the 'widths' in 'printColumnsText' represent? pixels? character count? text size? Couldn't find an exact info on the documentation.
@sreekanth-krishnan should be the same as other ESC/TCS devices, 1mm=8dots in normal cases.
So I guess we need to specify width in mm there?
@sreekanth-krishnan with dots
Hi @sreekanth-krishnan , I just read the API document carefully, and I found I was wrong for the previous post, as the API said:
/**
- 打印表格的一行,可以指定列宽、对齐方式
- @param colsTextArr 各列文本字符串数组
- @param colsWidthArr 各列宽度数组(以英文字符计算, 每个中文字符占两个英文字符, 每个宽度大于0)
- @param colsAlign 各列对齐方式(0居左, 1居中, 2居右)
- 备注: 三个参数的数组长度应该一致, 如果colsText[i]的宽度大于colsWidth[i], 则文本换行 */
It represent by character count (EN), every Chinese take 2 chars . I translated that comments information (API) as
/**
- Print a line of the table, can specify the with and alignment.
- @param colsTextArr - The array contains the text of each column in the line.
- @param colsWidthArr - The array contains the width of the column in the line (represents by character count in English, Chinese take 2 chars each word. The value must larger then 0)
- @param colsAlign - The array of the alignment of each column in the line (0-left,1-center,2-right) )
- Remarks: the length of colsTextArr, colsWidthArr and colsAlign must be the same. Line feeds when character count in colsText[i] is larger then colsWidth[i]. */
hope it can help.
That's really hepful. Thanks. But unfortunately when I use this method to print a table it doesn't print anything. Does it work on V1. Does it have any relation to firmware version? Any idea? It doesn't even work with their official demo app.
Plz check my demo first , it is in examples folder of source code
发自我的 iPhone
在 2017年8月11日,下午7:57,sreekanth-krishnan notifications@github.com 写道:
That's really hepful. Thanks. But unfortunately when I use this method to print a table it doesn't print anything. Does it work on V1. Does it have any relation to firmware version? Any idea? It doesn't even work with their official demo app.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
i have problem when print 4 column
Hey,
I finally get the permission part working just working on the printing part, can you show me some exmaples on how to call the prinintg method?
I tried to call that line by line like the following:
SunmiInnerPrinter.setAlignment(1);
SunmiInnerPrinter.printTextWithFont('Some Title, 'gh', 28);
SunmiInnerPrinter.lineWrap(1);
SunmiInnerPrinter.printTextWithFont('a long long sentence with bigger font, 'gh', 32);
SunmiInnerPrinter.lineWrap(1);
But seems the order will get messed by (because the printing method is asynchrously called?). Can you should me how print it properly using your library?
Thanks