开发者

Why doesn't IE show file download dialog for PDF with GWT Window.open()?

开发者 https://www.devze.com 2023-03-19 17:23 出处:网络
We are generating PDF documents for our customers and serving them with a Servlet. The following code works with Firefox, Chrome a开发者_StackOverflownd Opera, but not with any version of IE. The popu

We are generating PDF documents for our customers and serving them with a Servlet. The following code works with Firefox, Chrome a开发者_StackOverflownd Opera, but not with any version of IE. The popup window only flashes with IE but nothing happens. However, we can get the file download dialog to show by making a direct request to the servlet from the address bar in IE. We've tried with several ContentTypes (application/download, application/x-download, etc.)

Client side code:

String URL = "/files/pdf?pdfId=" + getPdfId();
Window.open(URL, "_blank", "");

Servlet serving the pdf as byte[]:

byte[] bytes = getFileAsByteArray();
BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(bytes));
BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());
response.setHeader("Content-Disposition", "attachment; filename=document.pdf");
response.setContentType("application/octet-stream");
response.setContentLength(bytes.length);
byte[] buffer = new byte[8192];
for (int length = 0; (length = in.read(buffer)) > 0;) {
    out.write(buffer, 0, length);
}
out.flush();
out.close();

Any thoughts on this?


Try this:

Content-Disposition: inline

instead of:

Content-Disposition: attachment;filename=document.pdf

Try this out, then tell something Found that if I use inline then I should NOT use filename=document.pdf, this will NOT work in IE. (other browsers ignore it)

You can read it here: http://indiwiz.com/2009/03/11/forcing-http-download/


It might be because of pdf plugin problem. Link to adobe site for more details


If you can't solve a problem - try to change something inside your problem! Try to send ziped pdf-file or another content. It should help you to find a root of trouble. If everything will work with zip file you don't need to send pdf-file


Try :

Window.open(GWT.getHostPageBaseURL()+URL,"","");

This might work ! I´m using :

com.google.gwt.user.client.Window.open(GWT.getHostPageBaseURL()+URL, "", "");   

and it's working just fine

0

精彩评论

暂无评论...
验证码 换一张
取 消