【发布时间】:2015-04-20 11:39:14
【问题描述】:
我的打印机 Zebra TTP 7030 通过 USB 连接到本地计算机。
我可以使用 javax.print API 打印数据,但我无法从打印机获取打印机状态或任何数据。
我试图从 Java printService 属性中获取打印机状态,但它没有返回有关打印机实时状态的任何有价值的信息。
Class<? extends Attribute>[] supportedAttributeCategories = (Class<? extends Attribute>[]) service.getSupportedAttributeCategories();
for (Class<? extends Attribute> category : supportedAttributeCategories) {
DocFlavor[] flavors = service.getSupportedDocFlavors();
for (DocFlavor flavo : flavors) {
Object supportedAttributeValues = service.getSupportedAttributeValues(category, flavo, service.getAttributes());
if (supportedAttributeValues instanceof Attribute) {
Attribute attr = (Attribute) supportedAttributeValues;
attribSet.add(attr);
} else if (supportedAttributeValues != null) {
Attribute[] attrs = (Attribute[]) supportedAttributeValues;
for (Attribute attr : attrs) {
attribSet.add(attr);
}
}
}
}
for (Attribute attr : attribSet) {
System.out.println(attr.getName());
System.out.println(service.getDefaultAttributeValue(attr.getCategory()));
}
Zebra 的 Link OS SDK 不支持我的打印机。有没有办法获取打印机状态?
解决方案:我使用JNA 为我的斑马打印机获取 Windows 打印机状态。
这里是如何使用 JNA 获取打印机信息的示例 How can i get a printer's make and model in Java?
【问题讨论】:
标签: java printing zebra-printers