我是热敏打印机的初学者,打印结果是:我试图在热敏打印机中打印Bangla: 我也尝试过其他字符集, 怎么解决这个?提前谢谢。
我的代码在这里: Main.java
private void print(){
PrintDefault pd=new PrintDefault();
String Str2 = null;
String text = null;
text = "আপনি কি ডাটা সংরক্ষন করতে চান";
pd.printString(Str2+"\n");
ByteArrayOutputStream bos=new ByteArrayOutputStream();
bos.reset();
bos.write(29);
bos.write((int)'V');
bos.write(1);
byte[] cutPaper=bos.toByteArray();
pd.printBytes(cutPaper);
}
PrintDefault.java
public void printString(String text) {
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
try {
byte[] bytes;
// important for umlaut chars
bytes = text.getBytes(StandardCharsets.UTF_8);
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void printBytes(byte[] bytes) {
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = service.createPrintJob();
try {
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);
} catch (Exception e) {
e.printStackTrace();
}
}