Question

I want to open a pdf file from DWR call. I am using DWR 2.0 Please guide me.

Was it helpful?

Solution

I am not able to understand that what do you mean by open pdf file. AS per my understanding of your question, you can use DWR to get the pdf file from server to client side. Then you have to display it with any client side techniques.

In DWR website you can find dwr.war file. It contains a example for downloading pdf files. You have put that file in any servlet container's web-apps folder. Then you can access the tutorial through http://localhost:8080/dwr/.

OTHER TIPS

Consider upgrading to DWR 3.

In DWR3 you will find a FileTransfer object...

HTML:

<form action="downloadFile.do">
  <div id="buttons">
    <input type="button" value="Back" id="mapback"    onClick="javascript:back();" class="Back" />
    <input type="button" value="SavePDF" id="SavePDF" onclick="return downloadPdfFile();" class="saveToPdfButton" />
    <input type="submit" value="Continue" id="continue" class="continue" />

  </div>
</form>

JavaScript:

function downloadPdfFile() {
  dwr.engine.setTimeout(59000);

  var callMetaData = {
  callback : downloadPdfCallback,
  exceptionHandler : hideLoadingAndSwitchOnSavePDFButton,
  errorHandler : hideLoadingAndSwitchOnSavePDFButton,
  preHook : showLoading,
  postHook : hideLoading
};

DWRAction.downloadPdfFile(callMetaData);

return false;
}

function downloadPdfCallback(data) {
   dwr.engine.openInDownload(data);
}

Java:

File pdfFile = new File(pdfFilename);
try {
      InputStream is = new BufferedInputStream(new FileInputStream(pdfFile));
       dwrPdfFile = new FileTransfer(pdfFile.getName(), "application/pdf", is);
     } catch (FileNotFoundException e) {
       LOGGER.error("Unable to find PDF file \'{}\'", pdfFile.getAbsoluteFile());
     } 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top