When using icon libraries like glyphicons there will be characters that are invalid in any other font resulting in an IllegalStateException because when an exception is thrown the writeTextPDFBox() method effectively does not call showText() at all before calling endText(). In this change a space is added so there is still some text there (I suppose a question mark could be added so developers know something is wrong, this is just cleaner).
The other change is a constructor that accepts a PDRectangle instead of a String for the pageFormat, allowing more flexibility when other standard or custom page sizes are needed.
On a side note, we are experimentally using this in Moqui Framework for server-side HTML rendering. You can see the code in the moqui/moqui-fop repository here on GitHub. More specifically, here is the HtmlRenderer class that uses CSSBox and CSSBoxPdf:
This class is loosely based on your demo code. There is also a servlet in the same package for streaming results, but just a warning it has code that is specific to Moqui Framework (ie the server side HTML generation, parameter handling, etc). All of this is open source so feel free to use or ask about anything of interest.
Many thanks for the PR; it's merged. I am glad to see CSSBox being used in other projects. The Moqui Framework seems very interesting to me, I will take a closer look.
When using icon libraries like glyphicons there will be characters that are invalid in any other font resulting in an IllegalStateException because when an exception is thrown the writeTextPDFBox() method effectively does not call showText() at all before calling endText(). In this change a space is added so there is still some text there (I suppose a question mark could be added so developers know something is wrong, this is just cleaner).
The other change is a constructor that accepts a PDRectangle instead of a String for the pageFormat, allowing more flexibility when other standard or custom page sizes are needed.
On a side note, we are experimentally using this in Moqui Framework for server-side HTML rendering. You can see the code in the moqui/moqui-fop repository here on GitHub. More specifically, here is the HtmlRenderer class that uses CSSBox and CSSBoxPdf:
https://github.com/moqui/moqui-fop/blob/master/src/main/groovy/org/moqui/fop/HtmlRenderer.groovy
This class is loosely based on your demo code. There is also a servlet in the same package for streaming results, but just a warning it has code that is specific to Moqui Framework (ie the server side HTML generation, parameter handling, etc). All of this is open source so feel free to use or ask about anything of interest.