【问题标题】:Formatting a receipt on a thermal epson TM-T20II printer在热敏 epson TM-T20II 打印机上格式化收据
【发布时间】: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);
}  

【问题讨论】:

    标签: java netbeans printing


    【解决方案1】:

    打印速度很慢,因为您是“逐字节”发送命令。 只需使用 ByteArrayOutputStream,“打印”其中的所有内容。 完成后,将其发送到您的打印机服务,oneshot。

    【讨论】:

    • 打印速度很慢,因为您正在“逐字节”发送命令。只需使用 ByteArrayOutputStream,“打印”其中的所有内容。完成后,将其发送到您的打印机服务,oneshot。感谢 BluEOS,ByteArrayOutputStream 提高了速度,但我仍然无法将同一行上的一个字符串向右对齐,另一个字符串向左对齐。有解决办法吗?
    • 您所需要的一切都已经在 OpenConcerto 中完成了:参见 code.openconcerto.org 的 /trunk/OpenConcerto/src/org/openconcerto/erp/core/sales/pos/io/DefaultTicketPrinter.java
    猜你喜欢
    • 2022-10-17
    • 2016-01-13
    • 2018-11-18
    • 2014-03-17
    • 2012-06-05
    • 2014-11-25
    • 1970-01-01
    • 2018-05-01
    • 2019-04-14
    相关资源
    最近更新 更多