4

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?

DavidPostill
  • 7,453
  • 9
  • 38
  • 57
NoNicknameSFDC
  • 221
  • 1
  • 5
  • 10
  • We can give you piece of advice, you will have to develop the code. Why don't you show what have you developed so far? – Aakash Apr 16 '15 at 10:15
  • possible duplicate of [How to print excel file and word document in java?](http://stackoverflow.com/questions/7336340/how-to-print-excel-file-and-word-document-in-java) – LittlePanda Apr 16 '15 at 10:41
  • @Aakash I have put my piece of code.. I can see the document in the printer spooler.. But it is not printing.. Could you see any issues with this? – NoNicknameSFDC Apr 16 '15 at 12:08
  • 1
    It's amazing how this question was never answered. – m4heshd Oct 07 '19 at 16:01

0 Answers0