我尝试将收据格式化为热敏打印机。打印机一次只能对齐一侧。使用ESC / POS命令重置并打印到另一个对齐使其打印缓慢,并且还丢失了它应该打印的前一行。 有没有办法在将收据发送到打印机之前格式化收据?我真的很感激任何帮助。
这是我的代码:
private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {
PrinterService printerService = new PrinterService();
System.out.println(printerService.getPrinters());
byte[] left = new byte[]{0x1b, 0x61, 0x00};
byte[] center = new byte[]{0x1b, 0x61, 0x01};
byte[] right = new byte[]{0x1b, 0x61, 0x02};
byte[] reset = new byte[]{0x1b, 0x40};
printerService.printBytes("EPSON TM-T20II", center);
printerService.printString("EPSON TM-T20II",
"\n\n PUMP FITNESS LIMITED"
+ "\n Address : 52763 NAIROBI"
+ "\n Tel : 0714183897"
+ "\n***********************************************"
+ "\n CASH SALE [ORIGINAL]");
printerService.printString("EPSON TM-T20II","\n++");
printerServiceprintBytes("EPSON TM-T20II", reset);
printerService.printBytes("EPSON TM-T20II", left);
printerService.printString("EPSON TM-T20II","\n RCT No.: " + sTrID);
printerService.printString("EPSON TM-T20II","++");
printerService.printBytes("EPSON TM-T20II", reset);
printerService.printBytes("EPSON TM-T20II", right);
printerService.printString("EPSON TM-T20II",
"Date : " + sTrDt + "\n Time : " + sTrTm);
printerService.printString("EPSON TM-T20II","\n++");
printerService.printBytes("EPSON TM-T20II", reset);
printerService.printBytes("EPSON TM-T20II", left);
printerService.printString("EPSON TM-T20II",
"\n Client No.: " + sID
+ "\n Received from : " + sClNm
+ "\n DESCRIPTION QTY AMT(Ksh)"
+ "\n***********************************************"
+ "\n " + sPSNm + "" + sQty + "" + sPSPrice
+ "\n Discount" + sDisc
+ "\n***********************************************"
+ "\n Total" + sNAmt
+ "\n Tendered Amount" + sCash
+ "\n Change" + sBal
+ "\n***********************************************"
+ "\n Pmt Mode : " + sPmtMode + "Cash Pnt:" + sCPNm
+ "\n Cashier : " + sUNm + "Shift No.: " + sShiftNo
+ "\n Powered By Pump Fitness Ltd."
+ "\n\n\n\n\n");
// cut that paper!
byte[] cutP = new byte[] { 0x1d, 'V', 1 };
printerService.printBytes("EPSON TM-T20II", cutP);
}
答案 0 :(得分:0)
打印速度很慢,因为你是sendind命令"逐字节"。 只需使用ByteArrayOutputStream," print"一切都在里面。 完成后,将其发送到您的printerServicen,oneshot。