We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to open dialog box after convert pdf file

Hello,
i’m using aspose word java library in web application, now i want to, how to pass stream when to convert word to pdf file after convert pdf its open in open dialog box like this,

Hi Tarique,

Thanks for your inquiry. In your case, you need to implement an
HTTPServlet before you send the document to the browser. Please
check the following code example. Hope this helps you.


<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”>/**

<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”>* Called from the web-app index page (because the POST method
is chosen for the input form).

<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”>*/

<span style=“font-family: “Courier New”; color: blue;” lang=“EN-GB”>protected<span style=“font-family: “Courier New”;” lang=“EN-GB”> void
doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException

<span style=“font-family: “Courier New”;” lang=“EN-GB”>{

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // Get the output
format selected by the user.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> String
formatType = “PDF”;

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> try

<span style=“font-family: “Courier New”;” lang=“EN-GB”> {

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // Open the
stream. Read only access is enough for Aspose.Words to load a document.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> InputStream stream = new FileInputStream(MYDir + “in.docx”);

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // Load the entire document into memory.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> com.aspose.words.Document doc = new com.aspose.words.Document(stream);

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // You can
close the stream now, it is no longer needed because the document is in memory.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> stream.close();

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // Once we have a document, we can save it to a file,
stream or send to the client’s browser.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // We just
send the document to the browser in this case.

<span style=“font-family: “Courier New”;” lang=“EN-GB”> sendToBrowser(doc, “AsposeWords”, formatType, true, response);

<span style=“font-family: “Courier New”;” lang=“EN-GB”> response.flushBuffer();

<span style=“font-family: “Courier New”;” lang=“EN-GB”> }

<span style=“font-family: “Courier New”;” lang=“EN-GB”> catch
(Exception e)

<span style=“font-family: “Courier New”;” lang=“EN-GB”> {

<span style=“font-family: “Courier New”;” lang=“EN-GB”> throw new RuntimeException(e);

<span style=“font-family: “Courier New”;” lang=“EN-GB”> }

<span style=“font-family: “Courier New”;” lang=“EN-GB”>}

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”>/**

<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”> * Sends the document
to the client’s browser.

<span style=“font-family: “Courier New”; color: green;” lang=“EN-GB”> */

<span style=“font-family: “Courier New”; color: blue;” lang=“EN-GB”>private<span style=“font-family: “Courier New”;” lang=“EN-GB”> void
sendToBrowser(Document doc, String demoName, String formatType, boolean
openNewWindow, HttpServletResponse response)

<span style=“font-family: “Courier New”;” lang=“EN-GB”> throws Exception

<span style=“font-family: “Courier New”;” lang=“EN-GB”>{

<span style=“font-family: “Courier New”;” lang=“EN-GB”> String extension = formatType;

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> String fileName = demoName + “.” + extension;

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> // Add
the Response header

<span style=“font-family: “Courier New”;” lang=“EN-GB”> if(openNewWindow)

<span style=“font-family: “Courier New”;” lang=“EN-GB”> response.setHeader(“content-disposition”,“attachment; filename=” + fileName);

<span style=“font-family: “Courier New”;” lang=“EN-GB”> else

<span style=“font-family: “Courier New”;” lang=“EN-GB”> response.addHeader(“content-disposition”,“inline; filename=” + fileName);

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”>

<span style=“font-family: “Courier New”;” lang=“EN-GB”> response.setContentType(“application/pdf”);

<span style=“font-family: “Courier New”;” lang=“EN-GB”> doc.save(response.getOutputStream(),
SaveFormat.PDF);

<span style=“font-family: “Courier New”;”>}