String filename = "e:\\test.txt";
//String filename = "e:\\test.jpg";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
DocFlavor[] d = service.getSupportedDocFlavors();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
InputStream i = doc.getStreamForBytes();
job.print(doc, pras);
Thread.sleep(10000);
}
我用这样只能打印出图片,不能打印txt和word等字符阿,应该是flavor的类型的问题,可是我的HP打印机不支持其他类型。应该怎样改才能打印字符呢?
在线等。。
//String filename = "e:\\test.jpg";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
DocFlavor[] d = service.getSupportedDocFlavors();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
InputStream i = doc.getStreamForBytes();
job.print(doc, pras);
Thread.sleep(10000);
}
我用这样只能打印出图片,不能打印txt和word等字符阿,应该是flavor的类型的问题,可是我的HP打印机不支持其他类型。应该怎样改才能打印字符呢?
在线等。。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货