【问题标题】:How to Access the printer queue within java如何在java中访问打印机队列
【发布时间】:2012-03-12 03:08:46
【问题描述】:

假设我从 MS Word 等程序打印了一些文档。假设我一次选择了 4 个文档,因此其中三个最终会在打印机队列中等待。我想访问并阅读一些有关在队列中等待的文档的信息。换句话说,我如何访问打印机队列并使用 java 读取有关任何待处理文件的信息?

有没有办法做到这一点?如果是这样,我该怎么做?

感谢您的帮助

【问题讨论】:

标签: java printing queue


【解决方案1】:

也许这个功能对你有帮助。

public Integer getExistQueuePrinter() {
    int queue = 0;
    PrintService myService = null;
    PrintService printService = PrintServiceLookup.lookupDefaultPrintService();

    if (printService != null) {

        //--> set printService.
        myService = printService;

        //--> get attributes from printService.
        AttributeSet attributes = printService.getAttributes();

        //--> loop attributes.
        for (Attribute a : attributes.toArray()) {
            String name = a.getName();
            String value = attributes.get(a.getClass()).toString();
            //System.out.println(name + " : " + value);
            if (name.equals("queued-job-count")) {
                //System.out.println(name + " : " + value);
                queue = Integer.parseInt(value);
            }
        }

        Object[] obj = attributes.toArray();
        //System.out.println("queue = " + obj[3]);

        return queue;
        /* debug.
         for (Object value : obj) {
         System.out.println("Color = " + value);
         }
         */

    }
    return null;
}

【讨论】:

  • 在我的平台上,Ubuntu 18.04,Oracle Java 11.0.9,属性名为QueuedJobCount
【解决方案2】:

在这里你可以找到通过java代码访问打印机的完整代码。

它提供了类似的功能

  1. 取消打印作业,
  2. 显示打印对话框,
  3. 打印文件等。

http://anonsvn.icesoft.org//repo/icepdf/tags/icepdf-3.1.0/icepdf/viewer/src/org/icepdf/ri/common/PrintHelper.java

【讨论】:

    猜你喜欢
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 2014-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多