【发布时间】:2018-02-01 17:49:55
【问题描述】:
我正在尝试将收据格式化为热敏打印机。打印机一次只能对齐一侧。使用 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);
}
【问题讨论】: