I've searched high and low for a solution, but I have just had no luckgetting any output. I have a function that reads a text file and sendsthe file to the printer.. however, it never reaches the printer,rather, it just sits and hangs in the printers print queue. (and ofcourse its no simple task to delete that queued print job with thesimple "cancel" option in windows... have to open up cmd and type "netstop spooler", then "net start spooler", then cancel the print job toget it to delete). It acts almost like it doesn't close the printstream when it reaches the end of the file, but I have no idea how toclose the stream once everything has been printed or spooled. Also aside note, it doesn't lock up the java app when the printer is set to"spool", but it does when it is set to accept an input stream...anyhow, here's the code thats been causing this headache for a week... public synchronized void PrintFile(String filename, Stringselectedprinter) { selectedprinter = (selectedprinter == null)? defaultprinter :selectedprinter; DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintRequestAttributeSet attrib = newHashPrintRequestAttributeSet(); PrintService svs[] =PrintServiceLookup.lookupPrintServices(flavor, attrib); int pindex = -1; for(int a = 0; a < svs.length; a++) { String tmp = svs[a].toString(); if(tmp.compareTo(selectedprinter) == 0){ pindex = a; } } // can't print if selected printer isn't found... if(pindex != -1) { PrintRequestAttributeSet aset = newHashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.ONE_SIDED); aset.add(new JobName(filename, null)); aset.add(new Copies(1)); DocPrintJob job = svs[pindex].createPrintJob(); try{ InputStream input = new BufferedInputStream(newFileInputStream(filename)); PrintJobListener pjlistener = new PrintJobAdapter() { public voidprintDataTransferCompleted(PrintJobEvent e) { System.out.println("Document sent toprinter."); } public void printJobCompleted(PrintJobEvent e) { System.out.println("Document was successfullyprinted."); } public void printJobCancelled(PrintJobEvent e) { System.out.println("Document printing wascancelled."); } public void printJobFailed(PrintJobEvent e){ System.out.println("Document failed toprint."); } public void printJobNoMoreEvents(PrintJobEvent e){ System.out.println("No more print events."); } public voidprintJobRequiresAttention(PrintJobEvent e) { System.out.println("Printer requiresattention."); } }; job.addPrintJobListener(pjlistener); DocAttributeSet das = new HashDocAttributeSet(); das.add(Sides.ONE_SIDED); Doc doc = new SimpleDoc(input, flavor, das); job.print(doc, aset); //input.close(); } catch(Exception t){t.printStackTrace();} } else { // can't find selected printer } }any help would be greatly appreciated. thanks in advance!
|
|
0
|
|
|
|
Reply
|
neriksmoen (1)
|
3/9/2007 2:11:28 AM |
|
|
0 Replies
388 Views
(page loaded in 0.042 seconds)
Similiar Articles: Print job gets to queue, but doesn't print - comp.lang.java ...I've searched high and low for a solution, but I have just had no luckgetting any output. I have a function that reads a text file and sendsthe file t... Print buffer jobs stuck in queue - comp.emacsPrint job gets to queue, but doesn't print - comp.lang.java ... Print Jobs are Stuck in the Print Queue HP Photosmart ... Printer won't print ... If the print job gets ... Remove All print jobs from a Print Queue - comp.os.vmsPrint job gets to queue, but doesn't print - comp.lang.java ... Print job gets to queue, but doesn't print - comp.lang.java ... HP-UX Print Problem - Print Job Prints ... solaris lp and lpq for remote NT print queue - comp.unix.solaris ...Print job gets to queue, but doesn't print - comp.lang.java ... solaris lp and lpq for remote NT print queue - comp.unix.solaris ... I am writing a script to send a print ... HP-UX Print Problem - Print Job Prints Repeatedly - comp.sys.hp ...Print job gets to queue, but doesn't print - comp.lang.java ... Print job gets to queue, but doesn't print - comp.lang.java ... HP-UX Print Problem - Print Job Prints ... How to remove/cancel print jobs in Solaris 10 - comp.unix.admin ...Print job gets to queue, but doesn't print - comp.lang.java ... lpstat -p question - comp.unix.solaris... to enable "lpsched" in solaris 10 ... cancel won't ... Acrobat6 Pro, "Failed to Print", suddenly can't print to pdf ...Print job gets to queue, but doesn't print - comp.lang.java ... Acrobat6 Pro, "Failed to Print", suddenly can't ..... the printer and the document just sets in the ... redirect print jobs - comp.unix.solarisPrint job gets to queue, but doesn't print - comp.lang.java ... How to tell if a process is paused? - comp.os.ms-windows ... redirect print job to file and process - how ... PDF won't print > 100 percent - comp.sys.mac.appsPrint job gets to queue, but doesn't print - comp.lang.java ... programmatically print PDF and specify printer, page size, and ... On submitting the ... HP/UX printing queues - comp.sys.hp.hpuxPrint job gets to queue, but doesn't print - comp.lang.java ... Print job gets to queue, but doesn't print - comp.lang.java ... HP-UX Print Problem - Print Job Prints ... Print job gets to queue, but doesn't print - comp.lang.java ...I've searched high and low for a solution, but I have just had no luckgetting any output. I have a function that reads a text file and sendsthe file t... Can't Print? Print Jobs are Stuck in the Print Queue HP Photosmart ...Printer won't print ... If the print job gets stuck in the print queue again, try printing a document from Notepad to ... 7/21/2012 4:55:08 AM
|