如何在java中获取printservice描述?

tzdcorbm  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(325)

如何从printservice获取打印机描述?

for (PrintService p : PrintServiceLookup.lookupPrintServices(null, null)) {
    System.out.println(printService.getAttribute(PrinterName.class));
    // System.out.println(printService.getAttribute(PrinterName.class));
}

9年前的问题“用java扩展打印机信息”还没有答案。似乎只有printername属性有效。
有没有办法得到打印机的描述?

kknvjkwl

kknvjkwl1#

java的解决方案是https://github.com/harwey/cups4j

CupsClient cupsClient = new CupsClient("127.0.0.1", 631);
         for (CupsPrinter cp : cupsClient.getPrinters()) {
            System.out.println("name" + " " + printer.getName());
            System.out.println("description" + " " + printer.getDescription());
            System.out.println("location" + " " + printer.getLocation());
            System.out.println("url" + " " + printer.getPrinterURL().toExternalForm());
            System.out.println("selected" + " " + printer.isDefault());
         }
      }

相关问题