0
我的打印机Zebra TTP 7030通过USB连接到本地计算机。如何从JAVA获得Zebra 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不支持我的打印机。有没有办法获得打印机状态?
SOLUTION:我用JNA来获得我的斑马打印机的Windows打印机状态。
下面是例子,如何使用JNA How can i get a printer's make and model in Java?