0
fis = new FileInputStream(file);
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; // FILE IS .txt TYPE
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
//pras.add(MediaSizeName.ISO_A4);
//pras.add(new Copies(1));
PrintService printService[] =PrintServiceLookup.lookupPrintServices(flavor, pras);
System.out.println("Print Service:"+printService);
PrintService defaultService =PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Default Service:"+defaultService);
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
if (service != null)
{
System.out.println("Selected Service"+service);
DocPrintJob job = service.createPrintJob();
job.addPrintJobListener(new MyPrintJobListener());
System.out.println("JOB:"+job);
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, das);
System.out.println("Start of Print");
job.print(doc, pras);
System.out.println("End of Print");
i=1;
}
else
{
i=0;
}
我正在處理一個Web應用程序,用戶希望打印保存在包含來自數據庫的詳細信息的文件中的數據,因爲他的查詢。我將上面的代碼放入一種方法,當它被調用時,它給出用戶的打印對話框,他可以從連接到他的機器的打印機列表中選擇打印機。 如果我嘗試打印到本地打印機,則文件將被髮送到C:\ WINDOWS \ system32 \ spool文件夾並進行打印。 但它不會在網絡打印機的情況下發生 我在網絡上的打印機是佳能MP280系列打印機 我能看到它在打印機列表中,但無法打印我的文件用java打印一個文件