我在通过热敏打印机打印字符串时遇到了一些问题......
它可以正确打印字符串的内容,但不会自动裁切纸张,而是保存在打印机中,也不会将其从打印机中取出。
- 代码 -
receipt = "Table #"+rs.getInt("table_id")+"\n\n"
+ "Food\t\tAdd\t\tRemove\n\n";
String defaultPrinter = PrintServiceLookup.lookupDefaultPrintService().getName();
System.out.println("Default printer: " + defaultPrinter);
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
InputStream is = new ByteArrayInputStream(receipt.getBytes("UTF8"));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc doc = new SimpleDoc(is, flavor, null);
DocPrintJob job = service.createPrintJob();
PrinterJob printJob = PrinterJob.getPrinterJob();
job.print(doc, null);
is.close();
有任何想法吗?