Java:如何从 JSP JSF 页面生成 PDF 文件?

发布于 2024-08-15 21:01:38 字数 110 浏览 3 评论 0原文

我需要从 JSP JSF 页面生成 PDF。我在网上搜索过,但没有找到任何关于如何执行此操作的示例。我需要转换整个页面,或者可能只转换该页面上的图表。

PS 我也在使用 IceFaces。

I need to generate a PDF from a JSP JSF page. I have searched the net, but I didn't found any examples of how should I do this. I need to transform the whole page, or maybe only the charts that I have on that page.

P.S. I'm also using IceFaces.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

初懵 2024-08-22 21:01:38

最简单的方法可能是 捕获 HTML< /a> 使用 过滤 并转换使用合适的 API 将其转换为 PDF,然后从 Filter 返回 application/pdf 数据。 IceFaces 部分提交支持可能可用于捕获组件树输出的子集,但您可能必须研究 IceFaces HTTP 请求的详细信息才能弄清楚如何利用它。

The easiest way is probably to capture the HTML using a Filter and convert that to PDF using a suitable API, then return the application/pdf data from the Filter. The IceFaces partial-submit support can probably be used to capture a subset of the component tree output, but you'll probably have to study the details of the IceFaces HTTP requests to figure out how to leverage that.

秉烛思 2024-08-22 21:01:38

据我所知,这不可能直接实现。您可以使用 Jasper Reports 在服务器端。或者,您可以使用 PrintPDF 这是一个 Firefox 插件来创建一个从网络浏览器。

As far as I know this isn't directly possible. You can use Jasper Reports to generate a pdf on the server side. Or, you can use PrintPDF which is a firefox plugin to create one from the web browser.

自由如风 2024-08-22 21:01:38

您可能需要以下内容:

  1. 捕获页面的 (X)HTML 输出。这可以通过您的 servlet 中的以下代码来完成:

    InputStream is = new URL("http://localhost/foo/page.jsf").openStream();
    
  2. 将捕获的内容转换为 pdf。请参阅飞碟渲染器(另外 - 此线程

  3. “发送”生成的 pdf。也就是说,只需将 pdf 写入(打印)到 response.getOutputStream(),并设置 Content-Type 标头 - response.setContentType("application/pdf")

You will probably need the following:

  1. Capture the (X)HTML output of your page. This can be done via the following code in a servlet of yours :

    InputStream is = new URL("http://localhost/foo/page.jsf").openStream();
    
  2. Transform the captured content to pdf. See the Flying Saucer renderer (and additionally - this thread)

  3. "Send" the generated pdf. That is, simply write (print) your pdf to the response.getOutputStream(), and set a Content-Type header - response.setContentType("application/pdf")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文