Unable to View PDF in Browser from a Servlet.
843841Feb 10 2006 — edited Dec 28 2006Hi,
I am facing a problem while trying to dynamically generate PDF from a Servlet and display it in the browser(IE 6.0 sp2)
The scenario is as follows:
i have a link which on clicking (using javascript) moves to a Servlet(say Dispatcher Servlet).This servlet forwards the control to another Servlet(say PDF Renderer Servlet) which generates the PDF and tries to display the results to the browser.
The PDF does get generated.
However in the pop-up i get a alert message to either open or save the PDF.But when i try to do so the message i get is that IE failed to communicate with the server.
The code i am using to display the PDF is as follows
---------------------------------------------------------------------
ByteArrayOutputStream outfile = pdfTransformer.transform(xmlString,container);
byte[] content = outfile.toByteArray();
response.setContentType("application/pdf");
response.setContentLength(content.length);
response.setHeader("Content-Disposition", "inline; filename=\"" + pdfName + "\"");
ServletOutputStream out= response.getOutputStream();
out.write(content);
out.flush();
out.close();
---------------------------------------------------------------------
Any suggestions would be a great help.
Thanks