Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't print file to printer using java applet
    text
    copied!<p>i have created java applet class, to print text file to printer, but when i running this program is nothing happend, in my printer status is no activity...</p> <p>this is my applet code (print function) : </p> <pre><code>public void testPrintDoPrivileged(){ AccessController.doPrivileged(new PrivilegedAction() { @Override public Object run() { FileInputStream textStream; try{ textStream = new FileInputStream("D:\\email_address.txt"); DocFlavor myFormat = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc myDoc = new SimpleDoc(textStream, myFormat, null); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(1)); aset.add(Sides.ONE_SIDED); PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); System.out.println("Printing to default printer: "+ printService.getName()); DocPrintJob job = printService.createPrintJob(); job.print(myDoc, aset); } catch( FileNotFoundException e1){ e1.printStackTrace(System.out); System.err.println(e1); } catch (PrintException ex) { System.err.println(ex); } return null; } }); } </code></pre> <p>and then by accident, i unplug my usb printer, then i try to test print again... in my printer(offline now) status is show a pending document.</p> <p>this is the picture : <img src="https://i.stack.imgur.com/42Dfa.jpg" alt="this is in offline printer(usb cable unplug)"></p> <p>there something wrong in my code or else..?.</p> <p>sorry for my english...</p> <p>thank you before...</p> <p><strong>Edit :</strong> </p> <p>the problem is in <em>DocFlavor</em>.</p> <p>my code running well in linux OS...</p> <p>because linux have much DocFlavor support...</p> <p>i use this code to check DocFlavor:</p> <pre><code>PrintService printServices = PrintServiceLookup.lookupDefaultPrintService(); DocFlavor[] docF = printServices.getSupportedDocFlavors(); for(int i = 0; i &lt; docF.length; i++){ System.out.println(docF[i].getMimeType()); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload