DOCX Compatibility

Hi,
I tried changing the template to docx. Also, I changed the saveformat to docx by setting it in the following manner.

doc.save(dstStream, SaveFormat.DOCX);

I am setting the filename ot the Response header in the following manner

response.setContentType("application/msword");
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.setHeader("Pragma", "public");
response.setHeader("Cache-control", "no-transform");

But, When the document is generated and it is opened, the error as attached in the screenshot is being shown and the details tab says that the file is corrupt.Does this mean that Aspose.words has issues supporting DOCX format?Please let me know.

Hi

Thanks for your request. This occurs because you specified incorrect Content Type. For DOCX format, you should use the following Content Type:

response.setContentType( * "application/vnd.openxmlformats-officedocument.wordprocessingml.document" * );

Hope this helps.
Best regards.

Hi,

I changed the content type.But, still the error is not gone.Kindly, let me know if I have to set any other thing apart from

  1. The template being in DOCX format
  2. Settign the ContentType
  3. Setting the Saveformat to docx

Regards,
Pavithra V.S

Hi

Thanks for your request. Please try using this code:

response.setHeader("content-disposition", "attachment; filename=out.docx");
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
doc.save(response.getOutputStream(), SaveFormat.DOCX);
response.flushBuffer();

Hope this helps.
Best regards.

Hi,
I did this.Even then, I find no change.The error still occurs.Can you tell me what else could be the possibility for this error?

Regards,
Pavithra V.S

Hi

Could you please attach your input document, your code and the output document here for testing? I will try to reproduce the problem on my side and provide you more information.
Best regards.