Re: [JAVA2D] Problem in printing on specfic printer on network
You are probably right that the printer doesn't recognise the contents. DocFlavor.BYTE_ARRAY.AUTOSENSE is really no more than a way to send a stream of bytes to your printer. If the byte stream is a Postscript document (for example) and the printer is a PCL-only printer then its just never going to work. Nothing we can do will ever change that. The onus is on you to only send that content to a device that understands it, or to first convert it into that format. But you should consider *why* you are using AUTOSENSE at all? That's bypassing Java and Windows printer-independent rendering. Graphics.drawString(...) via a PrinterJob will work on any device The listener methods presently will not tell you anything more than the JDK internally completed sending data to the print spooler. It will not tell you anything about whether the printing on the device really worked. -phil. jav...@javadesktop.org wrote: Hi Jennifer Sorry I wrongly wrote it is not printString it is printContent, so now I edited it. I am trying your suggestion but I think so the problem that my doc favor is not recognized by printer. When I debugged my program execution goes to the printDataTransferCompleted() and then printJobNoMoreEvents() methods of PrintJobListener interface but string is not getting printed. I have HP laserjet as my network printer. Thanks for your help Shashwat [Message sent by forum member 'shashwat_anand' (shashwat_anand)] http://forums.java.net/jive/thread.jspa?messageID=334130 === To unsubscribe, send email to lists...@java.sun.com and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to lists...@java.sun.com and include in the body of the message help. === To unsubscribe, send email to lists...@java.sun.com and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to lists...@java.sun.com and include in the body of the message help.
[JAVA2D] Problem in printing on specfic printer on network
Hi Everyone I am working one swing application which need to print on some specific printer on network. Method which I am using is given below. In this method i am passing the printer name as parameter and string which is to be printed is present in the class member [b]printString[/b]. public boolean print(String printerName) { boolean result = false; try { ByteArrayInputStream bais = new ByteArrayInputStream(printContent.getBytes()); PrintService[] services = PrinterJob.lookupPrintServices(); String [] printerNameList = new String[services.length]; for(int count = 0; count services.length; count++) { printerNameList[count] = services[count].getName(); if (printerNameList[count].equalsIgnoreCase(printerName)) { DocPrintJob job = services[count].createPrintJob(); DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; Doc doc = new SimpleDoc(printContent.getBytes(), flavor, null); PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet(); attributes.add(new Copies(1)); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, attributes); pjDone.waitForDone(); bais.close(); result = true; break; } } } catch(PrintException ex) { String message = Error on while printing the content on the printer : + ex.getMessage(); System.out.println(message); ApplicationLogger.getInstance().error(message); } catch(Exception ex) { String message = Error on while printing the content : + ex.getMessage(); System.out.println(message); ApplicationLogger.getInstance().error(message); } return result; } Here is the code for PrintJobWatcher class PrintJobWatcher { // true iff it is safe to close the print job's input stream boolean done = false; PrintJobWatcher(DocPrintJob job) { // Add a listener to the print job job.addPrintJobListener(new PrintJobAdapter() { public void printJobCanceled(PrintJobEvent event) { allDone(); } public void printJobCompleted(PrintJobEvent event) { allDone(); } public void printJobFailed(PrintJobEvent event) { allDone(); } public void printJobNoMoreEvents(PrintJobEvent event) { allDone(); } void allDone() { synchronized (PrintJobWatcher.this) { done = true; PrintJobWatcher.this.notify(); } } }); } public synchronized void waitForDone() { try { while (!done) { wait(); } } catch (InterruptedException e) { } } } But my string is not being printed. Please tell where I am doing mistake. Thanks in advance Shashwat [Message sent by forum member 'shashwat_anand' (shashwat_anand)] http://forums.java.net/jive/thread.jspa?messageID=333974 === To unsubscribe, send email to lists...@java.sun.com and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to lists...@java.sun.com and include in the body of the message help.
Re: [JAVA2D] Problem in printing on specfic printer on network
Hi Jennifer Sorry I wrongly wrote it is not printString it is printContent, so now I edited it. I am trying your suggestion but I think so the problem that my doc favor is not recognized by printer. When I debugged my program execution goes to the printDataTransferCompleted() and then printJobNoMoreEvents() methods of PrintJobListener interface but string is not getting printed. I have HP laserjet as my network printer. Thanks for your help Shashwat [Message sent by forum member 'shashwat_anand' (shashwat_anand)] http://forums.java.net/jive/thread.jspa?messageID=334130 === To unsubscribe, send email to lists...@java.sun.com and include in the body of the message signoff JAVA2D-INTEREST. For general help, send email to lists...@java.sun.com and include in the body of the message help.