Hi I have some code as below to print an image which works fine, however i need to print without a user dialog, this problem i have is when i remove the printer dialog the image doesn't print, the printer detects a document sent to it and prints a blank page. The printer i am using will only print PTR raster images, which when i use the dialog, it works fine but unless i can get the thing to print (and actually print) the application is pretty useless. The code is as follows:
public Boolean process(File[] files) throws Exception{ for(int i=0;i<files.length;i++){ String file = "C:\\images\\colour\\"+files[i].getName(); String filename = file; 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, DocFlavor.INPUT_STREAM.GIF, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.exit(0); } }; job.addPrintJobListener(listener); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); } } return true; }
Can anyone help? in desperate need of this to work!