Play框架:从使用Javascript进行绘图的模板生成PDF [英] Play Framework: Generate PDF from template that uses Javascript for graphing

查看:89
本文介绍了Play框架:从使用Javascript进行绘图的模板生成PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板,其中包含一些用于在浏览器中生成图形的Javascript.我想使用相同的模板来创建PDF并作为附件发送到电子邮件中.在这种情况下,将不会有浏览器/客户端交互.

I have a template that has some Javascript used to generate graphs in the browser. I would like to use that same template to create a PDF and send as an attachment in an e-mail. In this scenario, there would be no browser/client interaction.

我正在使用Play网站上提供的PDF模块,并且设法使PDF渲染正常工作.唯一的问题是,图形不会显示在PDF中,而其他所有静态文本却会显示.我假设图形没有出现在PDF中,因为在生成PDF之前未执行Javascript.

I am using the PDF module that is available from the Play website and I have managed to get the PDF rendering to work. The only issue is that the graphs don't show up in the PDF but all other static text does. I'm assuming the graphs aren't appearing in the PDF due to the Javascript not being executed prior to the PDF generation.

有人对如何解决这个问题有任何想法吗?

Does anyone have any ideas on how to get around this problem?

推荐答案

由于您使用的是Play框架,因此最简单的方法可能是使用Rhino. http://www.mozilla.org/rhino/这是Mozilla的Javascript实现,可在JVM,这是Play框架在其上运行的.您可能需要对Javascript进行一些更改,例如,如果Javascript使用浏览器Canvas API,则必须制作一个外观对象,该对象将这些绘图命令发送到PDF绘图对象而不是屏幕.或者,如果您想要的话,可以在两个地方都可以.

Since you are using the Play framework, the easiest way is likely to be using Rhino. http://www.mozilla.org/rhino/ That is Mozilla's implementation of Javascript to run on the JVM, which is what the Play framework runs on. You may have to make some changes to the Javascript, for instance if it uses the browser Canvas API you would have to make a facade object that sends those drawing commands to the PDF drawing object instead of the screen. Or to both places if that is what you want.

如果您提供有关Javascript图形代码的更多信息,您可能会得到更详细的答案.

You might get a more detailed answer if you give some more information about the Javascript graphing code.

这篇关于Play框架:从使用Javascript进行绘图的模板生成PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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