posted 16 years ago
Hi,
I am trying to open a pdf file in IE. But the problem is that it opens up a blank pdf page... When I download the pdf, its size is not 0 and it does contain the pdf author name,and title but its empty..
The code snippet
response.reset();
response.setHeader("Expires", "0");
response.setHeader("Cache-Control","cache");
response.setHeader("Pragma", "cache");
response.setContentType("application/pdf");
response.setHeader("Content-disposition", "attachment;filename=neha.pdf");
ServletOutputStream so = response.getOutputStream();
ByteArrayOutputStream output = new ByteArrayOutputStream();
InputStream in = new BufferedInputStream(new FileInputStream("neha.pdf"));
byte bytebuff[] = new byte[500];
for(int lengthread = 0; (lengthread = in.read(bytebuff)) != -1;){
output.write(bytebuff, 0, lengthread);
}
byte data[] = output.toByteArray();
response.setContentLength(data.length);
so.write(data);
in.close();
so.close();
Thanks a lot,
Neha