Problems with Word Docx ContentType

I have the following code:


DocumentTemplate doc = adminService.getDocumentById(params.id?.toLong())
byte[] responseData = adminService.convertDocxBytesToModel(doc.contentType, doc.data);

String myContentType = doc.getContentType()
println "myContentType: " + myContentType

int myContentSize = responseData.size()
println "myContentSize: " + myContentSize

response.contentType = myContentType
response.contentLength = myContentSize

response.outputStream << responseData

and
myContentSize shows as 45758
myContentType is reported as "application/vnd.openxmlformats-officedocument.wordprocessingml.document"

The file downloads as a *.docx file, but something is not right with it. If I open the file in Word and save-as, it’s fine. But without doing the save-as step, it’s not a valid word (xml) file.

Is there something else I need to set besides the content type? And is that content type wrong?

Thanks for any help,
Andy

Hi Andy,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Aspose.Words generated output document which shows the undesired behavior
  • Your expected document which shows the correct output. Please create this document using Microsoft Word application.
  • Please create a standalone runnable simple Java application (source code) that helps us reproduce your problem on our end and attach it here for testing.
  • Please share the details of the development environment (e.g. OS, .Java JDK versions) of the machine you're getting this problem on.
  • What version of Aspose.Words for Java are you using?

As soon as you get these pieces of information ready, we'll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click 'Reply' button that will bring you to the 'reply page' and there at the bottom you can include any attachments with that post by clicking the 'Add/Update' button.

Best regards,

Problem was the Byte-Order Mark. I had to do some wonky stuff to make it right.

Hi Andy,


It is great you were able to find what you were looking for. Please let us know any time you have any further queries.

Best regards,