如何在java中访问打印机队列 [英] How to Access the printer queue within java

查看:1866
本文介绍了如何在java中访问打印机队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Suppose that I printed some documents from a program like MS Word. Let's say I selected 4 documents at once, so three of them would end up waiting in the printer queue. I would like to access and read some information about the documents waiting in the queue. In other words, how can I access the printer queue and read information about any pending files with java?

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

Is there a way to do that? If so, how can I do it?

感谢您的帮助

推荐答案

也许此功能对您有所帮助。

maybe this function helpful for you.

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

这篇关于如何在java中访问打印机队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆