发现可用的打印服务
要发现所有可用的打印服务,我们可以使用 PrintServiceLookup
类。我们来看看如何:
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
public class DiscoveringAvailablePrintServices {
public static void main(String[] args) {
discoverPrintServices();
}
public static void discoverPrintServices() {
PrintService[] allPrintServices = PrintServiceLookup.lookupPrintServices(null, null);
for (Printservice printService : allPrintServices) {
System.out.println("Print service name: " + printService.getName());
}
}
}
该程序在 Windows 环境中执行时将打印如下内容:
Print service name: Fax
Print service name: Microsoft Print to PDF
Print service name: Microsoft XPS Document Viewer