【问题标题】:Printing through java code but job always stuck in queue通过java代码打印但作业总是卡在队列中
【发布时间】:2021-11-09 02:38:48
【问题描述】:

这是我要执行的代码。它工作正常,我在打印机队列中看到文档,但打印机不打印页面。

从其他应用打印不会卡在队列中。

知道问题出在哪里吗?

我的打印机是 USB001 端口上的 HP Deskjet 3512

public static void main(String[] args) {

    PrintService pservice = PrintServiceLookup.lookupDefaultPrintService();
    String printText = "Hello World";
    try {
        SimpleDoc doc;
        doc = new SimpleDoc(printText.getBytes(), javax.print.DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
        DocPrintJob job = pservice.createPrintJob();
        job.print(doc, new HashPrintRequestAttributeSet());
        System.out.println("Job sent to printer succesfully");

    } catch (Exception e) {
        e.printStackTrace();

    }

}

【问题讨论】:

    标签: java printing hardware


    【解决方案1】:

    有时您需要发送 Form Feed 来强制打印。

    InputStream ff = new ByteArrayInputStream("\f".getBytes());
    Doc docff = new SimpleDoc(ff, flavor, null);
    DocPrintJob jobff = service.createPrintJob();
    pjw = new PrintJobWatcher(jobff);
    

    【讨论】:

    • 感谢回复,此换页请求也卡在队列中。
    猜你喜欢
    • 2016-08-14
    • 2016-12-03
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    • 2019-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-12-03
    相关资源
    最近更新 更多