title: Displaying pdf in jsp
body: <p>I have written a jsp page to display contents of pdf, but end up with ascii codes in jsp. I want to display the contents of pdf in jsp. Whats the part that I have missed. When I try to write the read content in pdf it shows only ascii values and not in readable format</p>
  
  <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=${encoding}"&gt;&lt;/head&gt;
  
  &lt;%@page import="java.io.File"%&gt;
  &lt;%@page import="java.io.*"%&gt;
  &lt;%@page import="javax.servlet.*"%&gt;
  &lt;%@page import="com.itextpdf.text.Image"%&gt;
  &lt;%@page import="com.itextpdf.text.Document"%&gt;
  &lt;%@page import="com.itextpdf.text.DocumentException"%&gt;
  &lt;%@page import="com.itextpdf.text.pdf.PdfReader"%&gt;
  &lt;%@page import="com.itextpdf.text.pdf.PdfImportedPage"%&gt;
  &lt;%@page import="com.itextpdf.text.pdf.PdfWriter"%&gt;
  &lt;%@page import="com.itextpdf.text.pdf.PdfContentByte"%&gt;
  &lt;%@ page language="java" contentType="application/pdf; charset=UTF-8"
      pageEncoding="UTF-8"%&gt;
  
  &lt;%
      response.reset();
      response.setContentType("application/pdf");
      File file = new File("D:\\TNWRD_Documents\\CHAPTER_II.pdf");
      response.setHeader("Content-Type", "application/pdf");
      response.setHeader("Content-Disposition",
              "inline;filename=Saba_PhBill.pdf");
      response.setContentLength((int) file.length());
      response.setHeader("Content-Type",
              getServletContext().getMimeType(file.getName()));
      response.setHeader("Content-Length", String.valueOf(file.length()));
      //OPen an input stream to the file and post the file contents thru the
      //servlet output stream to the browser
      FileInputStream in = new FileInputStream(file);
      ServletOutputStream outs = response.getOutputStream();
      response.setContentLength(in.available());
      byte[] buf = new byte[8192];
      int c = 0;
      try {
          while ((c = in.read(buf, 0, buf.length)) &gt; 0) {
              //System.out.println("size:"+c);
              outs.write(buf, 0, c);
              out.write(outs.toString());
          }
  
      } catch (IOException ioe) {
          ioe.printStackTrace(System.out);
      } finally {
          outs.flush();
          outs.close();
          in.close();
      }
  %&gt;
  &lt;/html&gt;
  </code></pre>