4

I have an HTML web page (the parent) that contains a hyperlink. When clicked, it opens a new window and displays another HTML document (the child):

 <a href="/testhtml.html" target="_blank">Open Child</a>

Inside the child document are several links that are constructed like this:

 <a href="#" onclick='opener.window.location.href="/somewhere.html";
                   window.close();'>Make Parent Go Somewhere</a>

So the effect is that you can click on a link in the child window, it will cause the parent window to go to that new uri, and then close itself. This works wonderfully.

I'd like to do that same thing with a PDF as the child document. I can embed hyperlinks in the PDF just fine, or even embed Javascript:

  13 0 obj
  <<
  /Type /Action
  /S /JavaScript /JS
    (opener.window.location.href="/somewhere.html";)
  >>
 endobj

The Javascript gets triggered nicely, but the object "opener" is not defined. (ReferenceError: opener is not defined 1: Link:Mouse Up) Is what I'm looking to do even possible? What would be the object I would use to access the opening window's uri?

PS: If it's a problem, I do have some control over the user's target environment. I can specify that they use Acrobat Reader, and even a later version of it.

Clinton Pierce
  • 12,859
  • 15
  • 62
  • 90

2 Answers2

2

HTML and PDF don't use the same object model. None the less, it's possible to get HTML and PDF JS to talk to one another:

Getting notified when the user clicks a link in an embedded PDF

Community
  • 1
  • 1
Mark Storer
  • 15,672
  • 3
  • 42
  • 80
  • Looking at livedocs.adobe.com/flex/3/html/help.html?content=PDF_1.html it seems like you've got it backwards. This is for sending messages from the containing document into the PDF. I still can't get messages out from the PDF into the containing document. – Clinton Pierce May 19 '11 at 15:22
  • Then you're not calling it on the right objects. Can you update your question to show the script you're using in the PDF and HTML? – Mark Storer May 19 '11 at 17:08
  • Here's a ready made example that claims to do (pretty much) what I want -- send a message from the document to the surrounding HTML. http://www.windjack.com/WindJack/Browser2PDF/brwsr2acroJS.htm It just does not work and seems misguided. The API described in the Adobe document is for going the other way around. I can't really supply code (working or non) for something that just can't be done? – Clinton Pierce May 19 '11 at 18:22
  • The linked demo works fine for me, using Acrobat Pro 10.0.3 with FireFox 4.0.1 on Windows 7 64-bit. What PDF viewer/browser/OS are you using? – Mark Storer May 20 '11 at 00:38
0

One easy way of achieving your goal is to create a PDF hyperlink with href="javascript:myfunction()", and defining myfunction() in your HTML web page. The resulting HTML file would be something like:

<html>
<head>
 <script type="text/javascript">
    function myfunction(){
        alert("captcha!");
    }
 </script> 
</head>
<body>
<object data="myfunction.pdf" type="application/pdf" width="100%" height="100%">
</object>
</body>
</html>

And your hyperlink PDF object would be:

<</Type /Action /S /URI /URI (javascript:myfunction\(\))>>

Inside myfunction() you will be able to use the HTML object model as usual.

yms
  • 10,361
  • 3
  • 38
  • 68