0

我发现http://code.google.com/p/flying-saucer/哪个应该是最适合我的项目的解决方案。但文件似乎只能从文件中读取。

但我的情况是我想从代码中渲染,我不想保存一个临时的 XML 文件。例如renderToImageAutoSizeGraphics2DRenderer

static java.awt.image.BufferedImage renderToImageAutoSize(java.lang.String url, int width, int bufferedImageType) 从文档自动创建图像的静态实用方法,其中高度根据文档内容确定。

有没有办法让渲染器直接从内存中的 HTML 代码读取?

4

1 回答 1

2

Graphics2DRenderer不是实用程序类。您应该创建它的一个新实例。

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);

请参阅http://today.java.net/pub/a/today/2006/10/31/combine-facelets-and-flying-saucer-renderer.html#xhtml-to-image-conversion

于 2012-02-02T15:52:59.727 回答