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..
You need to close the "fos" stream. Also check whether the file that's generated on the server is actually a valid PDF file.
Also, you should get in the habit of Using Code Tags when posting code of any length. You're making it unnecessarily hard for people to read your code (and thus less likely for them to want to help you).
Joined: Jul 23, 2008
hey... I did close the FileOutputStream... It did not help... And the pdf getting generated on the server is valid..
Joined: Mar 22, 2005
You could try to remove some unnecessary complexity from the code by writing from the input stream directly to the servlet output stream (instead of using a ByteArrayOutputStream and byte in between).
You should put this in a servlet, not a JSP, JSPs have too many things happening behind the scenes (if you check your error logs you may find some of them).
Example: You probably get an error when you use response.getOutputStream() since for a typical JSP the response.getWriter() has already been called and you aren't allowed to call both. You tell IE that the content is a PDF but it gets an error page which is HTML and can't display it so it appears blank. Your error logs would display the problem though.
In Servlets everything that is going on is much more transparent, so this kind of operation happens with less issues and easier to debug code. For a real good example of a download servlet look at BalusC's blog: The FileServlet.
In particular your JSP almost certainly includes whitespace which is being written to the output ahead of the actual PDF content. That would make it not look like a PDF. So what Steve Luke says, yes. Put the code in a servlet.