从 Tomcat 提供的网页生成 PDF [英] Generating a PDF from a Tomcat-served webpage

查看:43
本文介绍了从 Tomcat 提供的网页生成 PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在试图弄清楚如何在服务器端从 Tomcat(应用程序是 Pentaho CE)提供的大量 javascript 网页生成 PDF 时遇到问题.内容是响应用户交互的仪表板.Pentaho(应用程序)通过 AJAX 调用动态地用各种内容替换 div.我想导出到 pdf 用户拥有仪表板的任何状态.我可以在服务器上放置什么没有限制,但我需要避免让客户端安装任何东西.

I'm having issues trying to figure out how to generate on server side a PDF from a javascript-heavy webpage that is served from Tomcat (the application is Pentaho CE). The content is a dashboard that responds to user interaction. Pentaho (the application) replaces divs dynamically with various content through AJAX calls. I'd like to export to pdf whatever state the user has the dashboard at. There are no restrictions on what I can put on the server, but I need to avoid having the client install anything.

我已经看过这个,以及其他一些 google-fu:JSP/HTML 页面到 PDF 的转换

I've taken a look at this, along with a bunch of other google-fu: JSP/HTML Page to PDF conversion

wkhtmltopdf 似乎是一个流行的选择;在我开始反对它之前,我有几个问题:

wkhtmltopdf seems to be a popular choice; before I start banging my head against it, I have a few questions:

  • wkhtmltopdf 能否处理转至由应用程序处理身份验证的受密码保护的 jsps?动态加载的 div 会破坏它吗?
  • 有没有办法将客户端视图返回给服务器进行处理?我阅读了有关屏幕捕获的信息...
  • 另一个可行的选择是通过服务器托管的 Web 浏览器自动本地访问服务器上的仪表板,并以这种方式生成 PDF...考虑到 Tomcat 和密码保护的限制,这可能吗这是由应用程序处理的?Pentaho 生成的 javascript 组件无法在应用程序之外访问.

谢谢!

好消息!wkhtmltopdf 有效!有点儿.我通过将登录详细信息放入查询字符串来通过密码验证,现在我得到了正确页面的 pdf.问题是没有显示任何 javascript 组件......(它们适用于 yahoo.com 之类的页面,所以也许我在这里遗漏了一些东西).

Good news! wkhtmltopdf works! Kind of. I got past the password authentication through putting the login details through a query string, and I'm getting a pdf of the correct page now. The issue is that no javascript components are showing up... (they work for pages like yahoo.com, so maybe I'm missing something here).

推荐答案

如果你有很多 AJAX 调用,你应该等待它们.使用 --javascript-delay x 参数,其中 x 是等待的时间.

If you have a lot of AJAX calls you should wait for them. Use the --javascript-delay x argument, where is x is the time to wait.

这篇关于从 Tomcat 提供的网页生成 PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆