1.检查发现打印机没有问题;
2.程序无报错,
3.打开word文件直接打印会显示有文件正在等待打印,
代码如下:
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService []pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, pservices,
defaultService, flavor, aset);
if(service != null){
try {
DocPrintJob pj =service.createPrintJob();
FileInputStream fis = new FileInputStream("C:\\Users\\Administrator\\Desktop\\"+name);//打印文档。"
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
pj.print(doc, aset);
} catch (FileNotFoundException fe) {
fe.printStackTrace();
} catch (PrintException e) {
e.printStackTrace();
}
}else {
System.out.println("打印失败");
}
求各位大神赐教!!