Wednesday, April 18, 2012

Save PDF using JSP

<%
java.io.File f=new java.io.File(imagepath,imagefile_name);
java.io.OutputStream outStream = response.getOutputStream();
response.setContentType( "application/pdf" );
  response.setContentLength((int)f.length());
         response.setHeader("Content-Disposition","attachment; filename=\"QR_Decoded_Actual_Document.pdf\"");
         response.setHeader("Cache-Control", "no-cache");
        byte[] buf = new byte[8192];
        java.io.FileInputStream inStream = new java.io.FileInputStream(f);
        int sizeRead = 0;
        while ((sizeRead = inStream.read(buf, 0, buf.length)) > 0) {

            outStream.write(buf, 0, sizeRead);
        }
        inStream.close();
        outStream.close();
%>

No comments:

Post a Comment