【发布时间】:2012-05-06 04:38:24
【问题描述】:
我正在使用 flysaucer 通过返回生成的 pdf 文档的 servlet 将 xhtml 文档呈现为 pdf。 xhtml 文档具有从另一个 servlet 请求的图像。图像 servlet 在返回适当的图像之前检查谁已登录。下面的代码显示了如何请求图像:
<img height="140" width="140" src="http://localhost:8080/myapp/servlet/DisplayPic" />
我的问题是图像的 http 请求来自 pdf 渲染器,而不是登录用户,因此图像 servlet 不知道谁已登录,因此不会返回所需的图像。
我目前正在使用下面的代码来渲染 xhtml 文档:
ITextRenderer renderer = new ITextRenderer();
renderer.setDocumentFromString(xhtmlDocumentAsString);
renderer.layout();
os = response.getOutputStream();
renderer.createPDF(os);
我需要在请求图像 servlet 时维护用户会话,或者向渲染器提供用于该特定 xhtml 元素的图像。我认为后者可以使用ReplacedElementFactory 来完成,但我无法挖掘出任何可以帮助我的示例代码。
【问题讨论】:
-
这太棒了!知道如何使它适用于 SVG 文件吗?
-
有一个功能要求让图片的 data-url 直接在飞碟中工作:code.google.com/p/flying-saucer/issues/detail?id=202
标签: java pdf-generation itext flying-saucer xhtmlrenderer