File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Print Documents Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Print Documents" Watch "Print Documents" New topic

Print Documents

Paolo Botta

Joined: Oct 13, 2005
Posts: 3
Hy, I'm translating an application from standard Windows environment to web/Servlet/JSP. This application is a data entry that at the end print some documents. These documents are in MSWord fromat and contains some DOCVARIABLE Fields to be filled. Now I know there is no pure java api to read MSWord documents, has anybody an idea of what is the better way. I mean save documents in RTF and use docvar, save documents in htm and ad some javascript code or any other format?
My Servlet or JSP has to fill the fields and send to the browser for printing.

Thanks for any clue
Paul Bourdeaux
Ranch Hand

Joined: May 24, 2004
Posts: 783
Hi Paolo,

Welcome to the ranch. First, please don't cross post your questions. Some ranchers who read several of the forums will get annoyed by cross posts and may be less likely to help out. Also, it makes it hard to follow the conversation when people are posting to two different places.

Now, with regards to your question...

My first suggestion would be to save the documents in xml format and parse through them like that. Microsoft Word 2003 and later have the ability to save into XML format, and it is pretty easy to parse through and populate whatever variables you need to before printing off the document.

There are also some APIs out there that can read Word documents. Off the top of my head, I believe the JACOB project, Jakarta POI, and OpenOffice all have API that can read and manipulate Word data. Google them and see what you come up with. Good Luck, and if you have more questions, ask!

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook
Paolo Botta

Joined: Oct 13, 2005
Posts: 3
Sorry for the croos, I was not sure the right place was JSP or Servlet.
First part of your answer is really intersting, I have to study it a little.
Second part can't be used, I have to compile the document on the server (AIX) and can't use jacob or any solution not pure java.

I tried to save (from WORD 2000) the doc in html and it produce a lot of html/xml and something else, but there are no true variables that I can compile. I'm going to try WORD 2003.

Thanks again
I agree. Here's the link:
subject: Print Documents
It's not a secret anymore!