我正在尝试将收据格式化到热敏打印机。打印机一次只能对齐一侧。使用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);
} 发布于 2018-02-01 17:49:55
打印速度很慢,因为您是“逐字节”地发送命令。只需使用ByteArrayOutputStream,“打印”其中的所有内容。完成后,发送到你的printerServicen,oneshot。
https://stackoverflow.com/questions/48559197
复制相似问题