title: ITextRenderer: Adjust page height to content
body: <p>I'm using ITextRenderer to generate a PDF from HTML and what I need to do is a cash register receipt.
  This receipt has dynamic width and, of course, dynamic content. This said, the height of content will always be different and right now I'm struggling to find a way of adjusting the height of the PDF page to the content.
  If it's too big the receipt has a long white section in the end and if it's to short the PDF get's paginated and I need it to be in one page only.</p>
  
  <p>I'm using <code>@page {size: Wpx Hpx;}</code> to set the page size, but it's almost impossible (would be very painful) to calculate the content height based on width and data.</p>
  
  <p>This is the code that generates the PDF:</p>
  
  <pre><code>ITextRenderer renderer = new ITextRenderer();
  
  byte[] bytes = htmlDocumentString.toString().getBytes("UTF-8");
  ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
  DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
  InputSource is = new InputSource(bais);
  Document doc = builder.parse(is);
  
  renderer.setDocument(doc, null);
  
  renderer.layout();
  renderer.createPDF(outputStream);
  outputStream.flush();
  outputStream.close();
  </code></pre>
  
  <p>I've also tried <code>renderer.getSharedContext().setPrint(false);</code>, but this throws a NPE.</p>
  
  <p>Also <code>@page {-fs-page-sequence: "none";}</code> without any luck.</p>