title: xhtmlrenderer creating PDFs of length 0
body: <p>I am new to <code>org.xhtmlrenderer.pdf.ITextRenderer</code> and have this problem:</p>
  
  <p>The PDFs that my test servlet streams to my Downloads folder are in fact empty files. </p>
  
  <p>The relevant method, <code>streamAndDeleteTheClob</code>, is shown below.</p>
  
  <p>The first try block is definitely not a problem.</p>
  
  <p>The server spends a lot of time in the second try block. No exception thrown.</p>
  
  <p>Can anyone suggest a solution to this problem or a good approach to to debugging it?</p>
  
  <p>Can anyone point me to essentially similar code that really works?</p>
  
  <p>Any help would be much appreciated.</p>
  
  <pre><code>res.setContentType("application/pdf");
  
  ServletOutputStream out = res.getOutputStream();
  
  ...
  
  private boolean streamAndDeleteTheClob(int pageid,
                                    Connection con,
                                    ServletOutputStream out) throws IOException, ServletException {
     Statement statement;
  
     Clob htmlpage;
  
     StringBuffer pdfbuf = new StringBuffer();
  
     final String pageToSendQuery = "SELECT text FROM page WHERE pageid = " + pageid;
  
     // create xhtml file as a CLOB (Oracle large character object) and stream it into StringBuffer pdfbuf
  
    try {  // definitely no problem in this block
      statement = con.createStatement();
      resultSet = statement.executeQuery(pageToSendQuery);
      if (resultSet.next()) {
        htmlpage = resultSet.getClob(1);
      } else {
        return true;
      }
      final Reader in = htmlpage.getCharacterStream();
      final char[] buffer = new char[4096];
      while ((in.read(buffer)) != -1) {
        pdfbuf.append(buffer);
      }            
    } catch (Exception ex) {       
      out.println("buffering CLOB failed: " + ex);
    }
  
    // create pdf from StringBuffer
  
    try {
      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      Document doc = builder.parse(new InputSource(new StringReader(pdfbuf.toString())));
      ITextRenderer renderer = new ITextRenderer();
      renderer.setDocument(doc, null);
      renderer.layout();
      renderer.createPDF(out);
      out.close();
    } catch (Exception ex) {
      out.println("streaming of pdf failed: " + ex);
  
    }
  
    deleteClob(con, pageid);
  
    return false;
  }
  </code></pre>