aspose file tools*
The moose likes JSP and the fly likes Jsp page export to Word Document without losing format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Jsp page export to Word Document without losing format" Watch "Jsp page export to Word Document without losing format" New topic
Author

Jsp page export to Word Document without losing format

lionel wilson
Greenhorn

Joined: May 31, 2010
Posts: 3
Hi,

How can I export a jsp page to word document without losing it's formating? Here is what I have it works fine but dosen't keep the formating like bold, italic ect..

<%@ page language="java" contentType="application/msword"
pageEncoding="ISO-8859-1" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page import="java.util.*" %>
<%@ taglib uri="http://java.fckeditor.net" prefix="FCK" %>

${letter.content}

Also when the word document opens and I save as it seems that it was not a .doc but .txt file.

Please Help
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42946
    
  70
You're not exporting a Word document, you're telling the browser that the HTML *is* a Word document - that won't work.

Either use a library like Apache POI to generate an actual Word document, or maybe generate an RTF document (which -being plain text with markup- is much easier than an actual DOC).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

You left out the important part of the code, namely the code which writes what you say is a Word document. My guess is that you aren't writing a Word document at all. That would be very hard to do in a JSP, given that a JSP is for producing text formats and Word documents aren't text formats.
lionel wilson
Greenhorn

Joined: May 31, 2010
Posts: 3
Thanks for your feedback! Ulf Dittmer can you explain to me how I would go about exporting in RTF? Are maybe direct me to a site...
Do you thinkg if I export in PDF it would keep the format?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61769
    
  67

Do you need a word document, or a PDF? They're not interchangeable.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
lionel wilson
Greenhorn

Joined: May 31, 2010
Posts: 3
He we can't get what we need by extracting in Word maybe we could extract in PDF and from there save as word. PDF 8 does keep the formatting from PDF to Word. So basically I would prefer Word but I was wondering if PDF keeps the formating.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18992
    
    8

Of course, the entire purpose of PDF is to format documents to be read by humans. So of course it "keeps the formatting".

If you can produce a PDF, then (according to you) your problem is solved. However since PDF isn't a text format, don't use a JSP to output it. Use a servlet instead.

Your original mistake was to assume that you could simply assert that your document was MS Word and you expected your HTML to be converted to Word. That isn't how it works. Likewise you can't just assert that your document is a PDF document, you actually have to produce data in the PDF format.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jsp page export to Word Document without losing format