When downloading a PDF document that is less than 8000 bytes long, the document is downloaded but is not displayed. How can I fix this?

Alessandro A. Garbagnati

I've had a similar problem before when I'm sending a PDF that I'm generate. The problem seems to happen when the PDF file is smaller than the buffer size of the response object (8K by default).

We've solved the problem with a little help from the buglist of Microsoft IE knowledge base. Setting the Content-Length in the response object, shoud do the trick.

Working code:

byte[] data = ...;
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(response.getOutputStream()));

For more discussion, see these two threads in the Servlets FAQ and the JSP FAQ.