Hope this helps: This had me stumped for quite a while
, but then I compared the saved PDF with the one returned from code and saw that the character encoding was wrong. You cannot use toString() here, at least not what I know. Instead, do this:
- Code: Select all
byte  ba;
ba = ((ByteArrayOutputStream)os).toByteArray();
The catch here (in my case where the same servlet is supposed to return either HTML or PDF) is to open your out's wisely. If you open a PrintWriter out = response.getWriter(); then you cannot open a binary stream.
It might even be possible to write os directly, but I have not had the time to try, yet.