File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to convert  a webpage to MS. word Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to convert  a webpage to MS. word" Watch "How to convert  a webpage to MS. word" New topic
Author

How to convert a webpage to MS. word

Fritz Largosa
Ranch Hand

Joined: Sep 12, 2005
Posts: 70
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

Joined: Jan 10, 2002
Posts: 61766
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Tien-Chih Wang
Greenhorn

Joined: Feb 23, 2003
Posts: 25
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

Joined: May 24, 2004
Posts: 783
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.


“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
Tien-Chih Wang
Greenhorn

Joined: Feb 23, 2003
Posts: 25
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

Joined: Sep 12, 2005
Posts: 70
Thanks a lot. Great help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert a webpage to MS. word