Java:如何在收据打印机上打印欧元符号

时间:2019-07-03 11:32:09

标签: java printing pos

我有一个Java应用程序,需要在Epson Tm20-II上打印欧元符号。

我尝试设置var euro使其包含在字符串中。

PrintService类中的printString方法

 public void printString(String printerName, String text) {

        // find the printService of name printerName
        DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();

        PrintService printService[] = PrintServiceLookup.lookupPrintServices(
                flavor, pras);
        PrintService service = findPrintService(printerName, printService);

        DocPrintJob job = service.createPrintJob();

        try {

            byte[] bytes;

            // important for umlaut chars
            bytes = text.getBytes("CP437");

            Doc doc = new SimpleDoc(bytes, flavor, null);


            job.print(doc, null);

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

主要功能:

        String euro = "\u20ac";
        PrinterService ps = new PrinterService();
        String toPrint = new String();

        toPrint = ("Hello world, 5" + euro);

        ps.printString(printer, toPrint);

不是打印€,而是打印?

0 个答案:

没有答案