2 Replies Latest reply on Mar 11, 2011 5:58 AM by Houda Lamkahkah

    download a PDF rather than opening it

    Mike Burton Newbie

      Hi Folks,


      My app produces a PDF report which I can show to the user by the code below, it opens in Preview ie the app that is registered to handle PDF files.  But I'd also like to allow the user to just save it to disk without viewing it, any ideas please?


      Regards,


      Mike Burton


      byte[] pdf= rpt.toPdf();        // Produce PDF into our byte array
      // Now render PDF bytes to browser...
      HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
      OutputStream os = response.getOutputStream();
      response.setContentType("application/pdf");
      response.setContentLength(pdf.length);
      response.setHeader("Content-disposition", "attachment; filename=\""+ rpt.getOutName()+ ".pdf\"");
      os.write(pdf);
      os.flush();
      os.close();
      facesContext.responseComplete();