title: How do I display a PDF onto a JSF page
body: <p>I want to display a PDF file onto my JSF page, I have check this <a href="https://stackoverflow.com/questions/1939778/how-to-display-a-pdf-document-in-jsf-page-in-iframe">how to display a pdf document in jsf page in iFrame</a>, but I dont want to display it on an iframe(since it will generate scroll bar). I just want to display the pdf onto a page like an image and able to give a width and height for it. </p>
  
  <p><strong>EDIT Hi BalusC. I still cant be able to display the pdf inline. Here is my code.</strong></p>
  
  <pre><code>@WebServlet(name = "pdfHandler", urlPatterns = {"/pdfHandler/*"})
  public class pdfHandler extends HttpServlet {
  
      private static final int DEFAULT_BUFFER_SIZE = 10240;
  
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
  
          String requestedFile = request.getPathInfo();
          File file = new File("/Users/KingdomHeart/Downloads/Test/pdf/" + requestedFile);
          response.reset();
          response.setContentType("application/pdf");
          response.setBufferSize(DEFAULT_BUFFER_SIZE);
          response.setHeader("Content-Length", String.valueOf(file.length()));
          response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
          BufferedInputStream input = null;
          BufferedOutputStream output = null;
          try{
              input = new BufferedInputStream(new FileInputStream(file), DEFAULT_BUFFER_SIZE);
              output = new BufferedOutputStream(response.getOutputStream(), DEFAULT_BUFFER_SIZE);
              byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
              int length;
              while((length = input.read(buffer)) &gt; 0){
                  output.write(buffer, 0, length);
              }
          }finally{
              output.close();
              input.close();
          }
      }
      ...
  }
  </code></pre>
  
  <p>It still prompt me to download the pdf file. The pdf file that get downloaded to my computer is the correct pdf file btw. Can u spot anything wrong?</p>