Issue while using the SAVE method

Hi,

I’m using Aspose.Words(java). the problem i’m facing is when i save the file via outputstream, the data gets corrupted (something like this…Îÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ). it looks fine when i save the data as a fileformat. any thoughts on whats going wrong?

method used :

doc.save(response.getOutputStream(), com.aspose.words.SaveFormat.DOC);

thanks,
prakash.m
LDC CONSULTANT.<span style=“font-size: 10pt; font-family: “Courier New”;”>

Hi
Thanks for your inquiry. Could you please provide me code example that will allow me to reproduce this problem? Also please attach input document(if you use template) and output document for investigating.
Best regards

Hi,

i have attached the code snippet, so basically after the transformation i’m using the save via stream on a jsp for the user.

thanks,
prakash.m

oh!, here is the template, you can have any values for mergefields.

thanks,
prakash.m

Hi, Prakash,
I think you have to flush the response buffer just after document save:

response.flushBuffer();

Best regards,

Hi,

thanks for the suggestion…

it didn’t help, used both outputstream.flush and response.flushbuffer()… here the save mehtod on OutputStream is able to write onto the Word document but the issue is with its encoding format which is causing the issue (when i open the file in a notepad i can see the letters/alphabets) . i tried setting both UTF-8 and ISO8859-1 on the jsp response object , it didnt help either.

so at this point i’m not sure how to implement Aspose Save method on a Stream for a webmodule, any suggestions will help.

FYI,
i have attached the transformed word document Aspose generated.

thanks,
prakash.m

Hi, Prakash,
MS Word asks for encoding just because your file is corrupted. Your application adds extra four bytes to the document’s begin: “0d 0a 0d 0a” (i.e. two ascii CR/LF). If you strip out these four bytes Word opens the doc as usual.
Unfortunately, I can’t exactly repeat your environment and your case. May be these four bytes already in response stream and you have to clear it before the doc, may be something wrong with your jsp template or servlet container settings…
For me, saving the doc to response stream works as advertized – you can check this in Aspose.Words.Demos.Web project (demos\Aspose.Words.Demos.Web folder in download zip). Please check DemoServlet.doPost(…) and sendToBrowser(…) methods (but these methods very similar with your ones).
Anyway you have to divide your code into small chunks if you want to localize the error. I believe Aspose.Words can’t add these four bites. So, please, try two things:

  1. Test Aspose.Words without jsp staff: save the generated document to a FileOutputStream and check it.
  2. Test jsp without Aspose.Words: Build a small test case that loads and sends ordinary MS Word file to the response stream.

Best Regards,

Hi,
thanks for the info “extra four bytes …” , clearing the outputstream before using it did the trick …

thanks,
prakash.m