Android How to print through Bluetooth printer with text alignment and also using table style?

1.7k views Asked by At

I am trying to print some information through bluetooth printer. I can print plain text. But I can't add any alignment and text format. Also i want to print some data like tableview.

Text format and alignment should be like this:-

enter image description here

Table formatted data should be like this:-

enter image description here

I need some help Please.

Here i include my code which i try:-

    String titleStr = "Title" + "\n\n";
    StringBuilder contentSb = new StringBuilder();
    contentSb.append("Item1      : 1221" + "\n");
    contentSb.append("Item2      : test" + "\n");
    StringBuilder content2Sb = new StringBuilder();
    content2Sb.append("BANK  : Us. 1.600" + "\n");
    String message  = "This is for test." + "\n\n";
    long milis      = System.currentTimeMillis();
    String date     = DateUtil.timeMilisToString(milis, "dd-MM-yy / HH:mm")  + "\n\n\n\n";

    byte[] titleByte    = titleStr.getBytes();
    byte[] content1Byte = contentSb.toString().getBytes();
    byte[] messageByte  = message.getBytes();
    byte[] content2Byte = content2Sb.toString().getBytes();
    byte[] dateByte     = date.getBytes();
    byte[] totalByte    = new byte[titleByte.length + content1Byte.length + messageByte.length +
                    content2Byte.length + dateByte.length];

    int offset = 0;
    System.arraycopy(titleByte, 0, totalByte, offset, titleByte.length);
    offset += titleByte.length;
    System.arraycopy(content1Byte, 0, totalByte, offset, content1Byte.length);
    offset += content1Byte.length;
    System.arraycopy(messageByte, 0, totalByte, offset, messageByte.length);
    offset += messageByte.length;
    System.arraycopy(content2Byte, 0, totalByte, offset, content2Byte.length);
    offset += content2Byte.length;
    System.arraycopy(dateByte, 0, totalByte, offset, dateByte.length);

    mmOutputStream.write(totalByte);
0

There are 0 answers