import javax.print.DocFlavor;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;
import javax.print.attribute.PrintServiceAttributeSet;
import javax.print.attribute.standard.PrinterName;
public class Main {
static public void main(String args[]) throws Exception {
PrintService pss[] = PrintServiceLookup.lookupPrintServices(null, null);
for (int i = 0; i < pss.length; ++i) {
System.out.println(pss[i]);
PrintService ps = pss[i];
PrintServiceAttributeSet psas = ps.getAttributes();
Attribute attributes[] = psas.toArray();
for (int j = 0; j < attributes.length; ++j) {
Attribute attribute = attributes[j];
System.out.println(" attribute: " + attribute.getName());
if (attribute instanceof PrinterName) {
System.out.println(" printer name: " + ((PrinterName) attribute).getValue());
}
}
DocFlavor supportedFlavors[] = ps.getSupportedDocFlavors();
for (int j = 0; j < supportedFlavors.length; ++j) {
System.out.println(" flavor: " + supportedFlavors[j]);
}
}
}
}
用Java列出当前系统打印机清单
最新推荐文章于 2021-09-03 10:57:42 发布
本文介绍了一个Java程序,该程序使用`javax.print`包中的类来查找系统中可用的打印服务,并列出每个打印服务的属性及支持的文档格式。
2293

被折叠的 条评论
为什么被折叠?



