We are generating PDF documents for our customers and serving them with a Servlet.
The following code works with Firefox, Chrome and 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:
instead of:
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/