当用户点击嵌入式PDF中的链接时收到通知 [英] Getting notified when the user clicks a link in an embedded PDF

查看:96
本文介绍了当用户点击嵌入式PDF中的链接时收到通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在页面中嵌入了PDF,我希望设置类似于JavaScript的回调函数,以便在用户单击PDF中的链接时调用。



有没有办法做到这一点? 请访问www.adobe.com/devnet/acrobat/javascript.html\"> Acrobat JS Reference 获取您要支持的最低版本,您将看到有关HostContainer对象的文档。



在PDF中:

  this.hostContainer.messageHandler = 
{
onMessage :函数(messageArray)
{
for(var i = 0; i< messageArray.length; i ++)
console.println(Message+ i +:+ messageArray [一世]);
},
onError:function(error,messageArray){},
onDisclose:function(){return true;}
};

在您的HTML中,假设您的PDF位于< object id = thePdf> 标签:

  function messageFunc(messageArray){
for var i = 0; i< messageArray.length; i ++)
alert(Message+ i +:+ messageArray [i]);
}

document.getElementById(thePdf)。messageHandler = {onMessage:messageFunc};

在您的PDF中,您还需要修改链接,以使它们具有JS动作发布消息到包含网页。这可以以编程方式完成(取决于您使用的语言/库而变化很大),或者在Acrobat Pro中手动完成。

 这个。 hostContainer.postMessage([urlClicked,http://blah.blah.blah ...]); 

不是很难,但没有人听说过它。如果在接下来几年的Adobe浏览器(Reader / Acrobat)以外的任何地方都可以使用它,那么我会被惊呆

如果你想

  var thePDF = document.getElementById(document.getElementById()返回一个消息, thePdf); 
thePDF.postMessage([This,is,an,array,too。]);

您甚至可以取出所有现有链接并通过包装打开PDF请求链接HTML页面...这种方式你可以给新的窗口名称,从JS关闭它们等等。你可以放下右边的时髦。



但是你必须能够更改PDF文件。


I got a PDF embedded in my page, and I'd like to set something like a javascript-callback to be called whenever the user clicks a link within the PDF.

Is there a way to accomplish this?

解决方案

If you check out the Acrobat JS Reference for the minimum version you want to support, you'll see documentation on the HostContainer object.

In the PDF:

this.hostContainer.messageHandler =
{
  onMessage: function(messageArray)
  {
    for(var i = 0; i < messageArray.length; i++)
      console.println("Message " + i + ": " + messageArray[i]);
  },
  onError: function(error, messageArray){ },
  onDisclose: function() {return true;}
};

In your HTML, assuming your PDF is inside an <object id="thePdf"> tag:

function messageFunc(messageArray) {
    for(var i = 0; i < messageArray.length; i++)
      alert("Message " + i + ": " + messageArray[i]);
}

document.getElementById("thePdf").messageHandler = { onMessage: messageFunc };

In your PDF, you'd also need to modify the links so they have a JS action that would post a message to the containing web page. This could be done programmatically (varying wildly depending on the language/library you use), or manually in Acrobat Pro.

this.hostContainer.postMessage(["urlClicked", "http://blah.blah.blah..."]);

Not terribly hard, but no one's ever heard of it. I'd be stunned if this worked anywhere outside an Adobe viewer (Reader/Acrobat) for the next several years.

If you want to send a message from your HTML to the PDF for some reason, it goes something like this:

var thePDF = document.getElementById("thePdf");
thePDF.postMessage(["This", "is", "an", "array", "too."]);

You could even yank out all the existing links and have the PDF request the links be opened by the wrapping HTML page... that way you can give the new windows names, close them from JS, etc. You can get down right snazzy.

But you have to be able to change the PDFs.

这篇关于当用户点击嵌入式PDF中的链接时收到通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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