Android :Using Bixolon thermal printer(SPP-R300) printing alignment

1.4k views Asked by At

How can i implement same row alignment of my text label for payment align left and it's value to right align? here's my code. is there a function from the SDK of bixolon SPP-R300 and how can i implement it. Thanks.

 JPOSprinting.mBixolonPrinter.printText("TOTAL AMOUNT PAID",alignmentLeft , textAttributeNormal, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
 JPOSprinting.mBixolonPrinter.printText(AmtPd +"\n", alignmentRight,textAttributeNormal, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
1

There are 1 answers

0
Roc Boronat On

let me share some code with you:

private final int LINE_CHARS = 42;

private void printTextColumns(String leftText, String rightText) {
    if (leftText.length() + rightText.length() + 1 > LINE_CHARS) { // If two Strings cannot fit in same line
        int alignment = BixolonPrinter.ALIGNMENT_LEFT;
        int attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(leftText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);

        alignment = BixolonPrinter.ALIGNMENT_RIGHT;
        attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(rightText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
    } else {
        int padding = LINE_CHARS - leftText.length() - rightText.length();
        String paddingChar = " ";
        for (int i = 0; i < padding; i++) {
            paddingChar = paddingChar.concat(" ");
        }

        int alignment = BixolonPrinter.ALIGNMENT_LEFT;
        int attribute = 0;
        attribute |= BixolonPrinter.TEXT_ATTRIBUTE_FONT_C;
        bixolonPrinter.printText(leftText + paddingChar + rightText, alignment, attribute, BixolonPrinter.TEXT_SIZE_HORIZONTAL1, false);
    }
}

Hope it fits what you need!