我有一个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);
不是打印€,而是打印?