I found http://code.google.com/p/flying-saucer/
which should be the most suitable solution for my project. But the documents only seem to be able to read from file.
But I my case I want to render from code and I don't want to save a temporary XML file. For example renderToImageAutoSize
in Graphics2DRenderer
static java.awt.image.BufferedImage renderToImageAutoSize(java.lang.String url, int width, int bufferedImageType) A static utility method to automatically create an image from a document, where height is determined based on document content.
Is there any way to let the renderer read directly from HTML code in memory?
Graphics2DRenderer
is not a utility class. You should create a new instance of it.
Graphics2DRenderer gr = new Graphics2DRenderer();
gr.setDocument(doc, uri);
gr.layout(g2, dim);
Rectangle minSize = r.getMinimumSize();
//create new image with this size
gr.render(newG2);