title: creating formatted PNG 'pages' of document using Java/Scala
body: <p>I have a document in a <code>scala.xml</code> tree (this is easy to convert to whatever else) that I'd like to take and turn into a series of PNG files.</p>
  
  <p>For example, the document might look like this:</p>
  
  <pre><code>&lt;doc
    title="My Document"
    author="John Doe"
    created="1 July 1977"
    published="19 July 1799"
  &gt;
    &lt;section heading="An Analysis of Multiparticles"&gt; &lt;!-- Section 1 --&gt;
      &lt;p&gt;Paragraph one goes here&lt;/p&gt; &lt;!-- INTRODUCTION! --&gt;
      &lt;p&gt;Paragraph two goes here&lt;/p&gt;
    &lt;/section&gt;
    &lt;section heading="Conclusion of Multiparticles"&gt; &lt;!-- Section 2 --&gt;
      &lt;p&gt;Paragraph one goes here&lt;/p&gt; &lt;!-- INTRODUCTION! --&gt;
      &lt;p&gt;Paragraph two goes here&lt;/p&gt;
    &lt;/section&gt;
  
  &lt;/doc&gt;
  </code></pre>
  
  <p>I'd then like to turn that document into a PNG that looks something like this minus the red lines under made-up words (I'd supply the rules for formatting, typefaces to use, etc etc):
  <img src="https://i.stack.imgur.com/pZ1Lh.png" alt="Image"></p>
  
  <p>And, if possible, longer documents should be able to be "paginated" into any number of PNG files that would flow into the next one after hitting say, 500px of height or something.</p>
  
  <p>If there is an existing Java library/package to do this that does any part of this (or a couple that manage to do it all put together)—great! Otherwise, I'd like to know where I should start for writing something to do this in Scala (preferably) or Java.</p>
  
  <p>Thanks!</p>