动态HTML转为PDF [英] Dynamic HTML to PDF

查看:128
本文介绍了动态HTML转为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够将动态HTML(通过javascript加载页面时呈现的HTML)转换为PDF。我知道有很多HTML到PDF的转换器,但我发现迄今为止没有找到动态HTML。



给定的工具应该能够成功地转换以下页面 - http://www.simile-widgets.org/timeline/



干杯
安东尼

更新:

我不需要这里的JavaScript功能......即我不需要能够交互屏幕......我只想要在PDF中捕获屏幕的最终呈现 - 就像在页面后拍照一样被加载。在这个例子中,我提供的JavaScript只是将div渲染到屏幕上,所以它不应该能够处理,只要它让页面呈现第一个。

解决方案

有没有办法可以做到。与在Web浏览器中享受完整的DOM和BOM访问相比,PDF中用于脚本的接口极其有限。您可以使用PDF实现的这种交互不容易从浏览器中的工作方式转换,并且几乎可以肯定需要手工编写。



您的示例页面有很多效果,PDF作为一种基本上静态的文档布局格式,根本无法复制。

编辑:


我只是想要在PDF中捕获屏幕的最终呈现


啊,那么这是一个更容易和更普遍的问题。



在这种情况下,您必须使用并自动化一个真正的网络浏览器(如Firefox),或者提供Web浏览器所有逻辑的工具包(如WebKit),然后:


  • 导出为PDF,或者使用内置 - 在Firefox中打印到文件的工具(打开背景图像/颜色)或PDF导出附件之一,或者浏览器的图像卡住(并将图像包含在PD中) F如果你必须)




参见这些 一些问题,讨论浏览器快照。


I need to be able to convert dynamic HTML (html that is rendered on page load by javascript) to a PDF. I know there are plenty of HTML to PDF converters but none of the ones I have found thus far cope with dynamic HTML.

The given tool should be able to successfully convert the following page - http://www.simile-widgets.org/timeline/

Cheers Anthony

UPDATE:

I don't need the JavaScript functionality here... i.e. i don't need to be able to interact screen... I just want the finial rendering of the screen to be captured in the PDF - like taking a photo after the page is loaded. And in the example I provided the javascript is only rendering divs to the screen so its nothing that it shouldn't be able to handle as long as it "lets" the "page" render first.

解决方案

There is no way it can be done. The interfaces available for scripts in PDF are extremely limited compared to the full DOM and BOM access you enjoy in a web browser. Such interaction as you can achieve in PDF is not readily translatable from how it works in a browser and would almost certainly need hand authoring.

Your example page has many effects that PDF, as an essentially static document layout format, simply cannot reproduce at all.

Edit:

I just want the finial rendering of the screen to be captured in the PDF

Ah, OK, that's a far easier and more common problem then.

In that case you'll have to use and automate a real web browser (like Firefox), or a toolkit that provides all the logic of a web browser (like WebKit), then either:

  • export to PDF, either using built-in tools like ‘Print to file’ in Firefox (with background images/colours turned on) or one of the PDF export add-ons, or

  • take a image snapsnot of the browser (and include the image in a PDF if you have to)

See these questions for some discussion of browser snapshotting.

这篇关于动态HTML转为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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