Search code examples
javaflying-saucer

Flying-saucer - html to png render always 16 pixels high


Does anyone have any experience with flying-saucer? I'm rendering an xhtml page to png, but the end result is always 16 pixels high. The rest gets cut off.

Java2DRenderer renderer = new Java2DRenderer(xHtmlFile, width); // Image height should be set automatically
BufferedImage buffImg = renderer.getImage(); // buffImg.getHeight always 16

The xhtml document is of course bigger.

It's basically one div with a few span elements in it, like this

<body>
    <div id="divThing">
        <span>text</span>
        <span>more text</span>
    </div>
<body>

Here's the css:

html
{
    color: #222;
    font-size: 1em;
    line-height: 1.4;
    font-size:20px;
}

body
{
    width:600px;
}

#divThing
{
    position: absolute;
    font-size:20px;
    word-wrap:break-word;  
    word-wrap:break-all;
    width:600px;
}

Solution

  • Ended up switching to Graphics2DRenderer class instead, which had a method renderToImageAutoSize. This worked better, using new File(File_To_Convert).toURI().toURL().toString() argument as suggested in this thread.