On-the-fly converstion of word to pdf

Is this possible to convert a word document to pdf using on-the-fly conversion(i.e. Without storing the pdf file in any of my physical disk location) & also wanted to open that pdf file in a browser using JAVA coding.

Is this possible to convert a word document to pdf using on-the-fly conversion(i.e. Without storing the pdf file in any of my physical disk location) & also wanted to open that pdf file in a browser using JAVA coding.

Hi Arpa,

Thanks for your inquiry. As your query pertains to Aspose.Words, so I’ve moving it to respective forum. There one of my colleagues will answer you soon.

Best Regards,

Hi Arpa,

Thanks for your interest in Aspose.Words.

I think, you need to implement an HTTPServlet before you can send the output Pdf document directly to the browser. You can find a demo example with full code here. Please see “sendToBrowser” function mentioned inside “Demo.java” tab. Using the servlet you can send the document to a browser like in the example code below which sends a .pdf file to the browser.

response.setContentType("application/pdf");
doc.save(response.getOutputStream(), SaveFormat.PDF);

I hope, this helps.

Best regards,

Hello Awais,

Greeting for the Day!!! I appreciate your quick reply.

Yes, the above mentioned code is help me a lot, but here you firstly converting the document file to pdf file and then save it into a physical disk location after that you are sending the pdf file directly to the browser to open in a browser window.

But, I don’t wanted to store that converted pdf file in any of my disk location because of memory usages. I want to use on-the-fly conversion.

Thanks in Advance.

Hi Arpa,

Thanks for your inquiry. You can use the following code in your servlet to be able to send the document to client’s browser and open it directly inside the browser window without saving it on disk.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

builder.insertHtml("hello world");
String fileName = "out.pdf";

response.addHeader("content-disposition", "inline; filename=" + fileName);

response.setContentType("application/pdf");

doc.save(response.getOutputStream(), SaveFormat.PDF);

I hope, this helps.

Best regards,

Hi Awais,
Great, this is what I wanted.
One last thing, as you are saving a html content under innerHtml method i.e. “hello world”.
Here, I wanted to upload a MS word document file, so is there any method to upload the word document directly with out storing and open in a browser.
Thanks In Advance.

Hi Arpa,
Thanks for your inquiry. Could you please clarify your requirement, do you want to load Word document into Aspose.Words’ DOM via URI?
PS: You can insert a Word document into another by using the code suggested in the following article:

Best regards,