【发布时间】:2012-03-12 03:08:46
【问题描述】:
假设我从 MS Word 等程序打印了一些文档。假设我一次选择了 4 个文档,因此其中三个最终会在打印机队列中等待。我想访问并阅读一些有关在队列中等待的文档的信息。换句话说,我如何访问打印机队列并使用 java 读取有关任何待处理文件的信息?
有没有办法做到这一点?如果是这样,我该怎么做?
感谢您的帮助
【问题讨论】:
-
你可能想看看printerQueue
假设我从 MS Word 等程序打印了一些文档。假设我一次选择了 4 个文档,因此其中三个最终会在打印机队列中等待。我想访问并阅读一些有关在队列中等待的文档的信息。换句话说,我如何访问打印机队列并使用 java 读取有关任何待处理文件的信息?
有没有办法做到这一点?如果是这样,我该怎么做?
感谢您的帮助
【问题讨论】:
也许这个功能对你有帮助。
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;
}
【讨论】:
QueuedJobCount。
在这里你可以找到通过java代码访问打印机的完整代码。
它提供了类似的功能
【讨论】: