posted 18 years ago
Hello,
I am trying to read a pdf file from database. I want the pdf file to be opened streaming in the sense the file should open automatically.
I am getting the bytes properly. I am seeting the response content type, content length properly. I am including part of my code below.
... response.setContentType("application/pdf");
response.setContentLength(pdfBytes.length);
ServletOutputstream out = response.getOutputStream();
out.write(pdfBytes);
out.flush(); ....
When I try to write the bytes using ServletOutputstream I get the window's window option of saving or opening the file. When I select open option, I get message saying "there is an error reading the file.
First I have to save the file to system then open using pdf editor. Then file opens fine. While trying to save file, the default file extension is '.do'. I have to manually save as .pdf file. Is it because I am trying to response out from action?
But, if I read the pdf file from file system rather than from database, the pdf file is read streaming and the file is opened directly and properly.
I dont know what is the problem. Any valuable suggestions please?
Thank You.
Rahi S.