如何在java中访问打印机队列

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

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

谢谢您的帮助

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

它提供了类似的function

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

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

也许这个function对你有帮助。

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