问题如题,请问怎么回事?我是用的网上找的代码打的,如下: PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; //打印PDF
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null) {
try {
DocPrintJob job = service.createPrintJob(); //创建打印作业
// FileInputStream fis = new FileInputStream(new File("d:\\test.txt")); //构造待打印的文件流
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(ouputStream, flavor, das); //建立打印文件格式
job.print(doc, pras); //进行文件的打印
}
catch(Exception e) {
e.printStackTrace();
}
}谢谢大家,还有,我打印出来的中文文档是乱码, 打印机是三星 ml-2150.
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; //打印PDF
PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, flavor, pras);
if (service != null) {
try {
DocPrintJob job = service.createPrintJob(); //创建打印作业
// FileInputStream fis = new FileInputStream(new File("d:\\test.txt")); //构造待打印的文件流
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(ouputStream, flavor, das); //建立打印文件格式
job.print(doc, pras); //进行文件的打印
}
catch(Exception e) {
e.printStackTrace();
}
}谢谢大家,还有,我打印出来的中文文档是乱码, 打印机是三星 ml-2150.
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货