0
我正在研究一個示例應用程序以在網絡打印機上打印文件。但我無法取得成功。夥計們請幫我解決這個問題。 要在網絡打印機上打印的Java應用程序
FileInputStream fis = new FileInputStream(file);
if (fis == null) {
System.out.print("No File");
return;
}
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
aset.add(new PrinterName("ipp:\\witnw21va\ipp\ITDepartment-HP4050", null));
//PrintServiceAttributeSet aset = HashPrintAttributeSet();
PrintService[] pservices = PrintServiceLookup.lookupPrintServices(flavor, aset);
if (service != null){
System.out.println("Default Printer: " + service.getName());
// Creating DocPrintJob
DocPrintJob job = service.createPrintJob();
try{
Doc doc = new SimpleDoc(fis,flavor,null);
PrintJobWatcher pjDone = new PrintJobWatcher(job);
job.print(doc,aset);
// Wait for the print job to be done
pjDone.waitForDone();
fis.close();
}
非常感謝。
歡迎StackOverflow上。事實上,您發佈的格式不完整,代碼不完整,沒有詳細說明它如何失敗。不幸的是,除了猜測之外,沒有什麼人可以提供。 – 2012-02-01 15:55:01
夥計們在他身上很容易,對於想要在網絡上打印的人有用 – 2015-10-18 06:10:21