小弟写了个类用来打印服务器端一个HTML页面,程序没有报错,打印对话框也出现了,打印机的任务栏里出现“正在进行后台打印”的字样。但打印机根本没有打出纸,完全没反应。打印机坏这个问题可以排除。问题还是出在程序上。但小弟没调出来。请大家帮忙看看,代码如下:public class Test { /**
* @param args
*/
public static void main(String[] args) {
try{
// TODO Auto-generated method stub
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup
.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
System.out.println("打印机:" + defaultService);
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
System.out.println("service::" + service);
if (service != null) {
DocPrintJob job = service.createPrintJob();// 创建打印作业
File uploadFile = new File("c://1.html");
System.out.println("文件长度:"+uploadFile.length());
FileInputStream fis = new FileInputStream(uploadFile);// 构造待打印的文件流
BufferedInputStream bis = new BufferedInputStream(fis);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(bis, flavor, das);// 建立打印文件格式
job.print(doc, pras); }
}catch(Exception e){
e.printStackTrace();
}
}}
* @param args
*/
public static void main(String[] args) {
try{
// TODO Auto-generated method stub
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup
.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
System.out.println("打印机:" + defaultService);
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, flavor, pras);
System.out.println("service::" + service);
if (service != null) {
DocPrintJob job = service.createPrintJob();// 创建打印作业
File uploadFile = new File("c://1.html");
System.out.println("文件长度:"+uploadFile.length());
FileInputStream fis = new FileInputStream(uploadFile);// 构造待打印的文件流
BufferedInputStream bis = new BufferedInputStream(fis);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(bis, flavor, das);// 建立打印文件格式
job.print(doc, pras); }
}catch(Exception e){
e.printStackTrace();
}
}}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货