Displaying PDf in the browser with JSP
843840Nov 13 2007 — edited Nov 16 2007Hi,
I am trying to open a pdf file with the help of JSP... the PDF file is comming but without any content...it is giving blank pages
My code is given below...can anyone figure out why its happening...
<%@ page import="java.io.*" %>
<%
response.setContentType("application/pdf");
response.setHeader("Content-Disposition","inline;filename=\"c:/test1.pdf\"");
File f = new File ("c:/test1.pdf");
InputStream in = new FileInputStream(f);
ByteArrayOutputStream out1 = new ByteArrayOutputStream();
int size = 0;
byte[] b = new byte[1024];
while ((size = in.read(b, 0, 1024)) > 0) {
out1.write(b, 0, size);
}
response.reset();
response.setContentLength(out1.size());
response.getWriter().write(new String(out1.toByteArray()));
%>