• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert a webpage to MS. word

 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a JSP page which provides a user with some form. I am wanting to give the user the ability to save the form as a MS Word document. I'm just wondering if this is even possible. If you know how or have any links, please let me know. Thanks.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64618
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It shouldn't be too hard to take the same data that you used to create the HTML page via JSP and format it in something like RTF that Word understands.

This, however, is not a job that a JSP is very well suited for. A servlet would be a much better choice, so I've moved this along to the Servlets forum for you.
 
Tien-Chih Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Here is the trick. Save your file to local html file. Use below tools
to tranform that html to winword format. Done!

http://www.w3.org/Tools/html2things.html

Tien-Chih Wang
 
Paul Bourdeaux
Ranch Hand
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want the processing to be done on the server instead of the client? i.e. the form has a link or button that says something like "Download as a word file"? If so, then you can look into the JACOB project or the OpenOffice APIs. It isn't too complex, but it does take some fiddling to get it right.

Alternatively, Word 2003 and later have the ability to read from and write to XML (I think it is going to be the default in Word 2005). It would be fairly easy to convert the page to XML and send it back as a .doc file. The drawback is that versions prior to 2003 would not be able to open the file.
 
Tien-Chih Wang
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do it on server side, you can create a template file. Feed in data and transform to RTF format.
The way it works is just like we manually did in local computer.

Few steps:

1. create a template file
2. Feed in data when user submit the form
3. Save the template file to another html file
4. Transform the html file to RTF document by some add-in tool(you can find some on above link I provide)
5. Redirect the browser to the new RTF document to let user download.

All steps can be done in One Click.

Tien-Chih Wang
 
Fritz Largosa
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot. Great help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic