热敏收据打印机自动切割问题

时间:2013-10-16 17:05:34

标签: java database string printing thermal-printer

我在通过热敏打印机打印字符串时遇到了一些问题...

它正确打印了字符串的内容,但它没有自动剪切纸张,它保存在打印机中,也没有将其从中取出。

- CODE -

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(); 

任何想法?

1 个答案:

答案 0 :(得分:0)

您应该按以下方式进行:

DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();  
byte[] bytes = {27, 100, 3};
DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
Doc doc = new SimpleDoc(bytes, flavor, null);
job.print(doc, null);