Hello,
I have a web app where you enter some data on the form page, then click a submit button and then the server side code should create a word file based on information from the form page. Now I can get my code to produce a word (.docx) file if I do a save to c:\test.docx but I'm having trouble trying to stream this file back to the end user so they could get the open/save dialog box. Below is some test code trying to get the stream to work.
Code:
public void setLicense() throws Exception {
com.aspose.words.License license = new com.aspose.words.License();
license.setLicense("C:\\projects\\poitest\\lib\\Aspose.Words.lic");
}
public void doDoc(ActionEvent event) {
System.out.println("in the doDoc event *******-***-*-*-*-*-*");
try {
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
this.setLicense();
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.write("hello world");
ServletOutputStream out = response.getOutputStream();
response.setHeader("Cache-Control", "max-age=30");
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
response.setHeader("Content-Disposition", "inline;filename=helloworld.docx");
doc.save(out, SaveFormat.DOCX);
context.responseComplete();
}
Results:
Page returns with PK
I'm using Aspose.Words.jdk16.jar from the 11.1 release. I've tried 11.0, & 10.8 same result. I working on a windows XP box, with Tomcat 6.0.18, and jsf
Thanks in advance for the help.