• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Print Word Document Programatically in Java

 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not Sure I quite understand what you are saying.
 
lowercase baba
Posts: 13091
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22815
132
Eclipse IDE Spring Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Be reasonable. You can't destroy everything. Where would you sit? How would you read a tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic