First, sorry if my english isn't really good :s
I look for a solution to generate a word version of a jsp page. I tested many solutions but none seems to work correctly. The one who gave me the better result was to use the MIME for Word :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<%@ page language="java" contentType="application/msword; charset=UTF-8" %>
But this solution works for IE only and forces the opening of the page in Word. But under the others browsers (chrome or firefox) it downloads me the code of my page in a .jsp
Another solution was to use POI, a Java API who I didn't success to set up.
Thanks in advance,
William
Since you thought of using POI,I suggest you to use docx4j, follow this link for setting up.
for importing docx4j library download latest docx4j.jar and add project build path or to use the following dependency for maven project
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>3.2.0</version>
</dependency>
use this code to convert your jsp to pdf
InputStream is = new FileInputStream(new File("your jsp file"));
WordprocessingMLPackage wordMLPackage = WordprocessingMLPackage.load(is);
PdfSettings pdfSettings = new PdfSettings();
OutputStream out = new FileOutputStream(new File("your pdf file"));
PdfConversion converter = new org.docx4j.convert.out.pdf.viaXSLFO.Conversion(wordMLPackage);
converter.output(out, pdfSettings);
Hope this solves your problem.
You are confusing generation of a .doc and transfert. Apache POI or docx4j suggested by Naresh kumar are for the generation of a .doc or .docx file on the server. And the contentType="application/msword; charset=UTF-8"
is for the transfert : it simply declares to the client that what follows should be a msword document.
generate a word version of a jsp page is hard to understand : jsp allows inclusion of dynamic elements in a textual document generally a HTML page, but it could be plain txt, or XML. But .doc or .docx are binary format that must be generated directly through a servlet using an appropriate tool.
You could also have a look to RTF format. It is (was ?) a textual representation of a msword document. As it is a text format, a JSP page could be used to include dynamic elements in a RTF page and then it would have sense to declare contentType="application/rtf; charset=UTF-8"
.
According to the page on wikipedia, last version of RTF was published by microsoft in 2008, so you could also try to use Open Document Format or Office Open XML. Both format allow to generate a document via XML, but beware the final document is a zip file containing other xml files so it is still a binary format.