【发布时间】:2011-10-12 15:28:26
【问题描述】:
我正在尝试使用 javax 进行打印。即使 javax 默认为单面,简单的打印作业也始终打印为双面,而且打印机设置为每张 1 页。
打印机是 HP 2015DN,这是我的代码:
String filename = "test.txt";
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService[] = PrintServiceLookup.lookupPrintServices(
flavor, pras);
PrintService defaultService = PrintServiceLookup
.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,
printService, defaultService, DocFlavor.INPUT_STREAM.AUTOSENSE, pras);
if (service != null) {
DocPrintJob job = service.createPrintJob();
FileInputStream fis = new FileInputStream(filename);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
pras.add(new Copies(1));
job.print(doc, pras);
fis.close();
}
我知道打印机可以单面打印,因为 Notepad++ 可以这样做..
任何帮助将不胜感激..谢谢..
【问题讨论】:
-
我建议您查看以下内容以更彻底地处理该问题:Printing with Attributes(Tray Control, Duplex, etc...) using javax.print library