//得到默认打印服务
PrintService se = PrintServiceLookup.lookupDefaultPrintService();
//得到打印服务列表
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
//打印数据类型
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//显示打印对话框
PrintService select = ServiceUI.printDialog(null,200,200,services,se,flavor,attrs);
//打印作业
DocPrintJob job = select.createPrintJob();
job.addPrintJobListener(new myPrintJob());
String str = "donbingdonbingdonbingdonbingdonbing";
ByteArrayInputStream os = new ByteArrayInputStream(str.getBytes());
DocAttributeSet das = new HashDocAttributeSet();
SimpleDoc doc = new SimpleDoc(os, flavor,null);
job.print(doc,attrs);以上的打印程序最后如何确定打印完成呢?总是没有完全打印结束就退出程序了.
class myPrintJob extends PrintJobAdapter {
public void printJobCompleted(PrintJobEvent pje) {
System.out.println("打印结束");
System.exit(0);
}
}
注册了以上的监听器,但此方法好像从没有被调用过.
DocPrintJob的print方法如何监听知道打印结束,现在打印不完.
String str = "donbingdonbingdonbingdonbingdonbing";
打印出来的最多只有donbing前面一段.
请问监听器应该如何写?
PrintService se = PrintServiceLookup.lookupDefaultPrintService();
//得到打印服务列表
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
//打印数据类型
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//显示打印对话框
PrintService select = ServiceUI.printDialog(null,200,200,services,se,flavor,attrs);
//打印作业
DocPrintJob job = select.createPrintJob();
job.addPrintJobListener(new myPrintJob());
String str = "donbingdonbingdonbingdonbingdonbing";
ByteArrayInputStream os = new ByteArrayInputStream(str.getBytes());
DocAttributeSet das = new HashDocAttributeSet();
SimpleDoc doc = new SimpleDoc(os, flavor,null);
job.print(doc,attrs);以上的打印程序最后如何确定打印完成呢?总是没有完全打印结束就退出程序了.
class myPrintJob extends PrintJobAdapter {
public void printJobCompleted(PrintJobEvent pje) {
System.out.println("打印结束");
System.exit(0);
}
}
注册了以上的监听器,但此方法好像从没有被调用过.
DocPrintJob的print方法如何监听知道打印结束,现在打印不完.
String str = "donbingdonbingdonbingdonbingdonbing";
打印出来的最多只有donbing前面一段.
请问监听器应该如何写?
用Thread.sleep(1000)停一下即能打的比较完全.
ByteArrayInputStream os = new ByteArrayInputStream(str.getBytes());
我最后没有调用os.close()关系,可是文档上说close()是无效的.
没人能回答一下吗?