简体   繁体   English

使用JavaScript填充HTML中的PDF字段

[英]Fill PDF fields from HTML with JavaScript

I've tried this example http://www.javabeat.net/javascript-communication-between-html-and-pdf-in-itext/ 我已经尝试了这个示例http://www.javabeat.net/javascript-communication-between-html-and-pdf-in-itext/

So I have PDF with embeded javascript and with input fields in PDF. 所以我有带有嵌入式javascript的PDF和PDF中的输入字段。

When I tried to start(index.html for example) on my computer in IE11, than everything works. 当我尝试在IE11中的计算机上启动(例如,index.html)时,一切正常。 So when I enter name and loginname and click on send to PDF, than input fields in PDF are filled. 因此,当我输入名称和登录名并单击“发送到PDF”时,将填写PDF中的输入字段。 But when I tried this example in chrome, than nothing happens. 但是当我在chrome中尝试此示例时,什么也没发生。

I tried to debugging javascript and error which I give but after scrolling the page(without scrolling I don't have error) is this: 我尝试调试给出的javascript和错误,但是在滚动页面后(不滚动,我没有错误)是这样的:

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('file://') does not match the recipient window's origin ('null')

I am the original author of the article you refer to. 我是您所引用文章的原始作者。 That code works because you are using the Adobe Reader plug-in in MSIE. 该代码有效,因为您正在MSIE中使用Adobe Reader插件。 It doesn't work with Chrome because Chrome uses the Chrome PDF Viewer to render PDF. 它不适用于Chrome,因为Chrome使用Chrome PDF查看器呈现PDF。 It won't work in Firefox either because Firefox uses pdf.js. 由于Firefox使用pdf.js,因此它在Firefox中也不起作用。 It won't work on a Mac either because the default PDF viewer on Apple computers is Preview. 由于苹果计算机上的默认PDF查看器为“预览”,因此它在Mac上也不起作用。

The example you refer too depends on whether or not JavaScript is supported in the viewer, and if it's supported, whether or not you can create a message handler. 您引用的示例也取决于查看器是否支持JavaScript,以及是否支持JavaScript,是否可以创建消息处理程序。 To my knowledge only Adobe Reader (and Acrobat) meet these requirements. 据我所知,只有Adobe Reader(和Acrobat)可以满足这些要求。

The code you copied from my book won't work in Chrome's PDF viewer, pdf.js, nor Apple preview. 您从我的书中复制的代码无法在Chrome的PDF查看器,pdf.js或Apple预览中使用。 There is no workaround to make it work with those viewers. 没有解决方法可以使其与那些查看器一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM