File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jsp page export to Word Document without losing format

 
lionel wilson
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20193
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you need a word document, or a PDF? They're not interchangeable.
 
lionel wilson
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20193
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic