1

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?

Thanks for the help

Leigh
  • 28,765
  • 10
  • 55
  • 103
Logan
  • 11
  • 2
  • 3
  • you might want to take a look at [printerQueue](http://stackoverflow.com/questions/3687184/java-check-if-file-is-in-print-queue-in-use) – Rakesh Mar 12 '12 at 05:17

2 Answers2

1

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;
}
Ruthe
  • 363
  • 4
  • 9
-1

Here you can find complete code for accessing printer through java code.

it provides functionality like

  1. cancel print job,
  2. display print dialog,
  3. print file etc..

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

Riddhish.Chaudhari
  • 833
  • 1
  • 8
  • 24