• Post Reply Bookmark Topic Watch Topic
  • New Topic

Print Word Document Programatically in Java  RSS feed

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

I want to Print Word Document Programatically.

My Word Document will be in Database in a BLOB Column and I want to send that to the Printer how Can I Do that.

The Below program is printing the Word Document silently but it is coming in unformatted way.

Please Help

 
Saloon Keeper
Posts: 4038
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some printer/driver combinations understand PDF files, but I'm not aware of any that know what to do with Word files. Furthermore, it looks like you're treating the contents of the file as text (which it is not) instead of binary (which its is).
 
Rohit Kedia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not Sure I quite understand what you are saying.
 
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Word documents have special characters in them that mean special things. In addition to what the text is, you need to know if the text should be bold, centered, italic, what font it is, what size, etc.

That data is written in the .doc file in a certain way. You need to know what those special codes are and how to interpret them. Try opening a .doc file in notepad, and you'll see a lot of gibberish. That's because notepad doesn't know how to read all that special stuff.

If you want to see all that, you'll need to figure out how to interpret the file. There may be 3rd party software packages you can get and use.
 
Rohit Kedia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

Can you suggest anything.

If you want to see all that, you'll need to figure out how to interpret the file. There may be 3rd party software packages you can get and use.
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rohit Kedia wrote:My Word Document will be in Database in a BLOB Column and I want to send that to the Printer how Can I Do that.

I doubt that there's a 100% solution, but JODConverter might be a place to start. Apache POI may also be able to do it but, from what I understand, its HWPF (Word) component is quite limited. Otherwise, there's always the OpenOffice SDK, but I suspect it'll involve quite a learning curve. There's also a product called docx4j, but I've never used it and have no idea how good it is.

It's also possible that you'll need a different solution for .doc and .docx files.

Finally, there are commercial programs, including (possibly) Word itself; although MS's own batch-style automators are either (a) abysmal, or (b) cost an arm and a leg.

Winston
 
Sheriff
Posts: 21136
87
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have MS Word installed, you can do it quite easily:
- store the BLOB in a temporary file (File.createTempFile)
- use java.awt.Desktop and its print(File) method.
- delete the file.
 
Tim Moores
Saloon Keeper
Posts: 4038
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:Apache POI may also be able to do it but, from what I understand, its HWPF (Word) component is quite limited.

POI would help somewhat with extracting text and layout information from a document, but it has no provisions for printing. Either JODConverter or Desktop.print look more promising.
 
Rohit Kedia
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
POI would help somewhat with extracting text and layout information from a document, but it has no provisions for printing. Either JODConverter or Desktop.print look more promising.


Can you share me some code snippets.

I had an alternate Solution to this Problem but I needed some assistance.

I will fetch all the BLOBS from Database and create a Word Document from it, is that possible ?
Also, I will be having multiple Blobs [different Word Files] and I want to put them Together in One Word Document , is that Possible ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!