Use byte array of PDF to display PDF in IE browser
843841Oct 21 2005 — edited Jun 3 2008I get byte array of PDF as input argument. I need to use byte array to display PDF in IE browser. I am writing code in doGet method of Servlet to accomplish this. However, PDF never gets displayed. I see Acrobat starting, but original PDF never gets displayed in browser.
I am using code below in doGet of Servlet:
resp.setContentType("application/pdf");
resp.setHeader("Expires", "0");
resp.setHeader("Cache-Control","must-revalidate, post-check=0,
pre-check=0");
resp.setHeader("Pragma", "public");
resp.setHeader("Pragma", "no-cache"); //HTTP 1.0
resp.setDateHeader("Expires", 0); //prevents caching at the proxy
server
resp.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
resp.setHeader("Cache-Control", "max-age=0");
resp.setHeader("Content-disposition", "inline; filename=stuff.pdf");
byte[] inBytes = getBytesOfPDF(...);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
if(inBytes !=null){
outStream.write(inBytes);
}
outStream.flush();
I added dummy name of PDF (stuff.pdf) for display, as I heard IE requires a file name with .pdf extension for display.
But I had no luck with the code above.
Any help with code will be appreciated.
sgho@aol.com