我正在参考P25 Demo Example使用蓝牙打印机打印收据。
一切正常。它也以定义的格式打印收据。但问题是每个新的String和StringBuilder对象都会打印很少的垃圾字符。
下面我要添加我的功能: -
private void printStruk() {
String titleStr = "Receipt" + "\n\n";
StringBuilder contentSb = new StringBuilder();
contentSb.append("IDPEL : 435353535435353" + "\n");
contentSb.append("NAMA : LORENSIUS WLT" + "\n");
contentSb.append("TRF/DAYA : 50/12244 VA" + "\n");
contentSb.append("BL/TH : 02/14" + "\n");
contentSb.append("ST/MTR : 0293232" + "\n");
contentSb.append("RP TAG : Rp. 100.000" + "\n");
contentSb.append("JPA REF :" + "\n");
StringBuilder content2Sb = new StringBuilder();
content2Sb.append("ADM BANK : Rp. 1.600" + "\n");
content2Sb.append("RP BAYAR : Rp. 101.600,00" + "\n");
byte[] titleByte = Printer.printfont(titleStr, FontDefine.FONT_24PX,FontDefine.Align_CENTER,
(byte)0x1A, PocketPos.LANGUAGE_ENGLISH);
byte[] content1Byte = Printer.printfont(contentSb.toString(), FontDefine.FONT_24PX,FontDefine.Align_LEFT,
(byte)0x1A, PocketPos.LANGUAGE_ENGLISH);
byte[] content2Byte = Printer.printfont(content2Sb.toString(), FontDefine.FONT_24PX,FontDefine.Align_LEFT,
(byte)0x1A, PocketPos.LANGUAGE_ENGLISH);
byte[] totalByte = new byte[titleByte.length + content1Byte.length +content2Byte.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(content2Byte, 0, totalByte, offset, content2Byte.length);
offset += content2Byte.length;
byte[] senddata = PocketPos.FramePack(PocketPos.FRAME_TOF_PRINT, totalByte, 0, totalByte.length);
sendData(senddata);
}
在上面的代码中,它在文件的中心打印标题字符串收据,但在此之前它还会打印一些垃圾字符。