How to convert a Document to Aspose.words Document from HttpServletResponse

Hello

I have a download functionality where I downlaod the file from HttpServletReponse.

I just write the ResponseEntity<byte[]> from Spring to HttpServletReponse.

Something like this.
https://stackoverflow.com/questions/5673260/downloading-a-file-from-spring-controllers

I have to do some implementation where I need to convert the HttpServletReponse to write a Aspose.words document.

Do some actions on Aspose words Document and then save it.

How can I achieve the functionality mentioned inside Stars in bold.

@rinkusm In your case you can save the document into a steam, then get bytes from the stream and write them into the response as described in the link you have provided above:

// Open the document
Document doc = new Document("C:\\Temp\\domeInputDocument.docx");

// Save the document to stream.
ByteOutputStream byteOutputStream = new ByteOutputStream();
doc.save(byteOutputStream, SaveFormat.PDF);

// Ge byte array from the stream.
byte[] docBytes = byteOutputStream.getBytes();

// Write bytes into the HttpServletReponse
// ................

If you need to load document form a byte array, you can use code like this:

byte[] docBytes = /* Get document bytes */;

ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(docBytes);
Document doc = new Document(byteArrayInputStream);