简体   繁体   English

获取所有活动的打印机

[英]Get all active Printers

The Printer-Api delivers an all printers of the system with Printer.getAllPrinters() . Printer-Api通过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 ? 可以帮助PrinterAttributes吗?

I am not sure about javaFX but you can achieve this using Java Print API's PrintService class. 我不确定javaFX,但是可以使用Java Print API的PrintService类实现此目的。

   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 现在,您可以遍历这些服务,并使用PrinterStatePrinterStateReason类来识别打印服务是否仍然可用

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 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM