【问题标题】:Thermal receipt printer problems with auto cut自动切割的热敏收据打印机问题
【发布时间】:2013-10-16 17:05:33
【问题描述】:

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

它可以正确打印字符串的内容,但它不会自动切纸,它保存在打印机中,也不会从打印机中取出。

--代码--

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

有什么想法吗?

【问题讨论】:

    标签: java database string printing thermal-printer


    【解决方案1】:

    你应该这样做:

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

    【讨论】:

    • 在哪里指定需要打印的特定字符串?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-14
    • 2017-03-12
    • 1970-01-01
    • 2013-07-04
    • 1970-01-01
    相关资源
    最近更新 更多