-6

I am trying to print excel file and word document to printer, but I don't know how to do it in Java.

Can anyone please help me and provide the code example?

Pshemo
  • 122,468
  • 25
  • 185
  • 269
Ahmed Ali
  • 31
  • 1
  • 1
  • 1
  • 2
    You also want us to do your work for you? These things can be found on google and we're not really big on doing other peoples work for them. If you have an actual question about how something is done, then ask that. – Nicholas Sep 07 '11 at 15:22
  • 1
    Voting to close: this is not a place for "I need the source code" type questions. – Hovercraft Full Of Eels Sep 07 '11 at 15:23
  • Hello Nicholas and Hovercraft..am a newbie to java. i have already searched google for printing word doc and excel files. But the sources says Use Office Org tools or Apache POI. but no detailed explanation. so after getting vexed with that. i again came to stack overflow to ask for help to get source code.. – Ahmed Ali Sep 07 '11 at 16:23
  • http://stackoverflow.com/questions/18437594/angularjs-call-other-scope-which-in-iframe/21733164#21733164 – Abhishek bhutra Feb 13 '14 at 08:44

3 Answers3

8
Desktop.getDesktop().print(new File("resume.doc"));
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
4

I found that if you seeking for source code, surely someone would vote you down. What you need should be an idea, or some hint to the solution only.

For printing Office documents from java, One way is to call .NET from java, but this one is very slow and if you want to integrate the source code, you need a bridge. If you want to write serious projects, this method seems too weak.

Another way is to use the Apache POI, as indicated by Nicholas. But POI also have some problem render Office documents. The positive sides is that it can be stable compared with calling .NET

For the java desktop way, seeing from java API, it seems to leave the solution to your OS. I am not sure about it. You can try it.

Anyway it is not a good way to print Microsoft things from Java, same applies to print PDF documents from .NET or other Microsoft things. Sigh!

Alex
  • 370
  • 1
  • 6
  • 11
  • To print PDF document, you can utilize the Sun PDF Renderer library, it is quite good. For text document print, it is quite simple with Java API, such as DocPrintJob or PrinterJob. – Alex Jan 10 '12 at 04:24
  • +1 for educating on SO usage and helping rather than instantly voting down. – Andy Sep 29 '12 at 10:07
2

Apache POI is one of the more useful libraries for doing MS Word on java.

And Java already has a printing library

Nicholas
  • 7,403
  • 10
  • 48
  • 76
  • 1
    Our requirement is we can't use third party tools or jar files which we have to buy. They suggested me to complete the requirement by using open source jar files and by using java. No office org tools, etc; So i specifically asked the source code. If not you help me to reach my requirement by providing required information. Do that favour.It will be helpful for me. – Ahmed Ali Sep 07 '11 at 16:29
  • Apache POI is Open-Source. If you want to do it yourself, go read the Microsoft documentation on how to parse a spreadsheet(Beware, it's not as much fun as you might think). – Nicholas Sep 07 '11 at 16:40