title: iText(Sharp) - how to avoid creating a blank page?
body: <p>I'm generating a PDF document using iTextSharp version 5.5.7, using their "streaming" mode - by which I mean I'm not specifying the location of every piece of text, I'm just adding Paragraphs to the Document and letting iTextSharp figure out where to draw them.  The text I'm outputting is the result of a report generator, so it is different every time.</p>
  
  <p>The problem I'm running into is this: imagine that, given the page size and the selected font, I can fit 40 lines of text on a page.  I output 40 Paragraphs, then I output a blank Paragraph (contents=" "), then an image that fills an entire page.  iTextSharp does exactly what I tell it - I end up with one page full of text, a blank page, and then a page containing my image.</p>
  
  <p>But now my document looks funny - there is this unexpectedly blank page in the middle of everything.</p>
  
  <p>I can't just say "don't output any blank lines" because of course that blank line might show up after only 20 lines of text, in which case it has to be there.  I need some way to either tell iTextSharp "include this paragraph only if it's not the only thing on a page" or else somehow detect that the page is blank in OnEndPage() and suppress its output (without screwing up my page numbers).</p>
  
  <p>Any suggestions on how I can do this?</p>
  
  <p>ADDED LATER</p>
  
  <p>Output from the report generator:</p>
  
  <pre><code>&lt;html&gt;
  &lt;p&gt;Information header&lt;/p&gt; 
  &lt;p&gt;Detail&lt;/p&gt;
  &lt;p&gt;Detail&lt;/p&gt;
  &lt;p&gt;Detail&lt;/p&gt;
  &lt;p&gt;&lt;/p&gt;  &lt;!-- Blank line inserted by report generator for clarity --&gt;
  &lt;p&gt;Information header&lt;/p&gt;
  &lt;p&gt;Detail&lt;/p&gt;
  &lt;p&gt;Detail&lt;/p&gt;
  &lt;p&gt;Detail&lt;/p&gt;
  ...
  &lt;p&gt;Detail&lt;/p&gt;  &lt;!-- just by random happenstance this is the last line that will fit on the first page --&gt;
  &lt;p&gt;&lt;/p&gt;   &lt;!-- This line happens to be blank, I have no control over it --&gt;
  &lt;img src="blah blah"&gt;&lt;/image&gt;
  </code></pre>
  
  <p>My (pseudo) code:</p>
  
  <pre><code>foreach (HtmlNode node in htmlFromReportGenerator)
  {
     if (node is text)
        pdfDoc.Add(new Paragraph(node.text));
     else if (node is image)
        pdfDoc.Add(new Image(node.image));
  }
  </code></pre>