我一直在尝试使用热敏打印机“Bixolon SRP-F310”并使用JAVA的PrintService打印一些文本。检测到打印机并且在调用打印功能时没有异常。我可以在杯子的Web界面看到打印事件被调用。但是,打印机不打印并显示错误消息“找不到页面!”可以在杯子的网络界面中看到。任何帮助将不胜感激。我已经包含了杯子网页界面和错误日志的截图。杯的使用JAVA在“Bixolon热敏打印机”上打印,“未找到任何页面!”错误
import javax.print.*;
import java.util.Arrays;
import java.util.List;
public class Printer {
static Printer INSTANCE;
public static void main(String[] args) {
INSTANCE = new Printer();
List<PrintService> services = INSTANCE.getServicesByName("BIXOLON_SRP-F310");
if(services == null) {
throw new RuntimeException("No printer services available");
}
INSTANCE.printServices(services);
try {
INSTANCE.print(services.get(0), "Hello");
} catch (Exception e) {
e.printStackTrace();
}
}
public List<PrintService> getServicesByName(String serviceName) {
//Find printer service by name
AttributeSet aset = new HashAttributeSet();
aset.add(new PrinterName(serviceName, null));
return Arrays.asList(PrintServiceLookup.lookupPrintServices(null, aset));
}
public void print(PrintService service, String printData) throws Exception {
if(service == null) {
throw new Exception("Service is not valid");
}
if(printData == null) {
throw new Exception("Nothing to print");
}
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
pras.add(new Copies(1));
pras.add(new PrinterResolution(180,180,PrinterResolution.DPI));
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
das.add(new PrinterResolution(180,180,PrinterResolution.DPI));
byte[] desc = printData.getBytes();
Doc doc = new SimpleDoc(desc, DocFlavor.BYTE_ARRAY.AUTOSENSE, das);
try {
job.print(doc, pras);
} catch (Exception e) {
e.printStackTrace();
}
}
public void printServices(List<PrintService> services) {
System.out.println("Printer Services found:");
for (PrintService service : services) {
System.out.println("\t" + service);
}
}
}
Web界面:
错误日志:
您是否配置了打印机?就像重置它的IP地址一样,因为在IP上你必须通过CUP传递数据。 – 2014-12-29 14:05:47
是的,我已经做到了,没有运气。 – yuva 2015-01-15 17:21:23