0

The Printer-Api delivers an all printers of the system with Printer.getAllPrinters().

The problem is that the user does not realize that the being selected printer is active.

Are there opportunities only to obtain the active printers?

Could help the PrinterAttributes?

espirio
  • 189
  • 14

1 Answers1

0

I am not sure about javaFX but you can achieve this using Java Print API's PrintService class.

   DocFlavor flavor = DocFlavor.INPUT_STREAM.POSTSCRIPT;
   PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
   aset.add(MediaSizeName.ISO_A4);
   PrintService[] pservices =
             PrintServiceLookup.lookupPrintServices(flavor, aset);

Now you can iterate through these services and use PrinterState and PrinterStateReason Classes to identify whether a print service is still available or not

For Example:

       PrinterState prnState = (PrinterState)service.getAttribute(
                                              PrinterState.class);
        if (prnState == PrinterState.STOPPED) {
            PrinterStateReasons prnStateReasons =
                (PrinterStateReasons)service.getAttribute(
                                             PrinterStateReasons.class);
            if ((prnStateReasons != null) &&
                (prnStateReasons.containsKey(PrinterStateReason.SHUTDOWN)))
            {
                throw new PrinterException("PrintService is no longer available.");
            }
        }

Hope this helps

Sanjeev
  • 9,876
  • 2
  • 22
  • 33