mazenrashed / Printooth

A well documented, high-level Android interface that makes printing via bluetooth printers easier
Mozilla Public License 2.0
396 stars 112 forks source link

Two Printables in same line won't dsiplay correct way #100

Open HIMESH1018 opened 1 year ago

HIMESH1018 commented 1 year ago
    val printableTotal = TextPrintable.Builder()
        .setText("Total")
        .setAlignment(DefaultPrinter.ALIGNMENT_LEFT)
        .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
        .build()

    val printableTotalValue = TextPrintable.Builder()
        .setText("20000")
        .setAlignment(DefaultPrinter.ALIGNMENT_RIGHT)
        .setEmphasizedMode(DefaultPrinter.EMPHASIZED_MODE_NORMAL)
        .setLineSpacing(10)
        .setNewLinesAfter(5)
        .build()`

print ")

HIMESH1018 commented 1 year ago

@mazenrashed

SnapperNewbie commented 1 year ago

You have to format your string. I format my Strings in a method like this (32 Characters in Line for my Printer)

private String formatForColum (String item, String price) {
float f1 = Float.parseFloat(price);
String formattedPrice = String.format("%.02f", f1); //2 Decimals

String column1Format = "%-24.24s";  // fixed size 24 characters, left aligned
String column2Format = "%7.7s";   // fixed size 7 characters, right aligned
String formatInfo = column1Format + " " + column2Format;

return String.format(formatInfo, item, formattedPrice);
}