Print job gets to queue, but doesn't print

  • Follow


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:













7/21/2012 4:55:08 AM


Reply: