爱普生epos sdk收据对齐问题 [英] Epson epos sdk receipt alignment issue

查看:255
本文介绍了爱普生epos sdk收据对齐问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用epson ePOS SDK for android。
i需要打印收据,菜单名称左对齐,价格在同一行右边对齐,但不能正常工作,
我的临时解决方案是添加一些Feed线来制作它价格对齐,是否可以让两个文本在同一行左右对齐?
(下面的附件,请忽略问号符号)

i'm currently using epson ePOS SDK for android. i need to print the receipt that menu name align to the left and its price align to the right in the same line but it doesn't work properly, my temporary solution is add some feed line to make its price align right, is it possible to have both text align left and right in the same line ? (Attachments below and please ignore question mark symbols)

                mPrinter.addTextAlign(Printer.ALIGN_LEFT);
                mPrinter.addFeedLine(0);
                textData.append(menuName);
                mPrinter.addText(textData.toString());
                textData.delete(0, textData.length());
                mPrinter.addFeedLine(0);

                //print price
                mPrinter.addTextAlign(Printer.ALIGN_RIGHT);
                textData.append(price + "Y" + "\n");
                mPrinter.addText(textData.toString());
                textData.delete(0, textData.length());
                mPrinter.addFeedLine(0);

推荐答案

80mm就像每行42列......可以轻松填充:

80mm is like 42 columns per line ...which can be easily padded:

mPrinter.addText(padLine(menuName, price + "¥", 42) + "\n");

所需的字符串操作方法看起来很相似:

the required String manipulation methods look alike:

/** utility: pads two strings to columns per line */
protected String padLine(@Nullable String partOne, @Nullable String partTwo, int columnsPerLine){
    if(partOne == null) {partOne = "";}
    if(partTwo == null) {partTwo = "";}
    String concat;
    if((partOne.length() + partTwo.length()) > columnsPerLine) {
        concat = partOne + " " + partTwo;
    } else {
        int padding = columnsPerLine - (partOne.length() + partTwo.length());
        concat = partOne + repeat(" ", padding) + partTwo;
    }
    return concat;
}

/** utility: string repeat */
protected String repeat(String str, int i){
    return new String(new char[i]).replace("\0", str);
}

在填充之前,应该将价格格式化为货币。

one should format the price to currency, before padding it.

使它真正完美......当 String concat 超过长度 42 ,然后 String partOne 应该被多余的长度截断 - 并再次连接。超过 int columnsPerLine 很可能会搞砸输出。

to make it truly "flawless" ... when String concat exceeds length 42, then String partOne should be truncated by the excess length - and be concatenated, once again. exceeding int columnsPerLine will most likely mess up the output.

这篇关于爱普生epos sdk收据对齐问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆