我正在研究在网络打印机上用java实现打印的项目,打印机没有配置。我在打印机服务查找总是返回 null 时遇到问题。
在 Java 应用程序中,是否有在未配置的打印机上打印文件?
下面的代码无助于检测打印机。
public int printDoc(InputStream is) throws PrintException, FileNotFoundException {
PrintService printService=PrintServiceLookup.lookupDefaultPrintService();
DocPrintJob job = printService.createPrintJob();
job.addPrintJobListener(new PrintJobAdapter() {
public void printDataTransferCompleted(PrintJobEvent event){
System.out.println("transfer complete");
}
public void printJobNoMoreEvents(PrintJobEvent event){
System.out.println("received no more events");
}
});
Doc doc=new SimpleDoc(is, DocFlavor.INPUT_STREAM.AUTOSENSE, null);
// Doc doc=new SimpleDoc(fis, DocFlavor.INPUT_STREAM.JPEG, null);
PrintRequestAttributeSet attrib=new HashPrintRequestAttributeSet();
attrib.add(new Copies(1));
String printeraddr= "ipp://blrprt01.blr.network18.com/23Flr_Printer1";
PrinterName prName =new PrinterName(printeraddr, null);
attrib.add(prName);
job.print(doc, attrib);
return 0;
}