I have a .doc file in my system and I want to send that doc file to the printer using Java.
I am using the POI Apache library.
How will I send the doc file to Printer?
Code:
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocPrintJob job = PrintServiceLookup.lookupDefaultPrintService().createPrintJob();
String fileName = "C:/Users/pnadigar/Desktop/11.doc";
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
InputStream fis = new BufferedInputStream(new FileInputStream(fileName));
POIFSFileSystem fs = new POIFSFileSystem(fis);
HWPFDocument docc = new HWPFDocument(fs);
Doc doc = new SimpleDoc(new ByteArrayInputStream(docc.getDataStream()), flavor, null);
job.print(doc, pras);
fis.close();
When I use this code I can see the document in the printer spooler, but it is not printing.
How can I resolve this?