These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

How to pass messages to Acrobat embedded in HTML page?

jim_merry
Registered: Jul 18 2007
Posts: 58

Is it possible to pass Acrobat a user defined message from within an HTML page? If so, what is the best way to do this? or is it possible to invoke Javascript routines remotely?

I want to have buttons/links in an HTML page that control the behavior of content displayed in a PDF document embedded in the same HTML page and displayed in the Reader. Specifically, I want to control display of named views of 3D content in a 3D Annot in the PDF document.

Jim Merry, VP 3D PDF, Tetra 4D, jim [dot] merry [at] tetra4d [dot] com

My Product Information:
Acrobat Standard 8.1.2, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, you can do this, but it's not a simple scripting task.

On this Page:

http://www.windjack.com/resources/howto.php

Scroll down to the "Extreme JavaScript for Acrobat" section and look at the "IE Browser/Acrobat intercommunication " sample.

All the HTML code is exposed and you can save the PDF demo locally to examine the code.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
Hi Thomp,

I have a similar problem.
I am using adobe acrobat 9 pro, my requirement is to trigger hidden submit button in PDF via Submit button in html page(basically PDF is embedded in html page).

I tried using postMessage as mentioned in below example but, it is not working.

If you can send any code examples that works with adobe 9 pro that would be great.

Thanks in advance.

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
It may not be Acrobat that's the problem. The whole HTML/PDF message passing system is dependant on a number of factors, primarily the security settings on both sides, but also the brower types and versions. Try it out on different setups and open up your browser security. Make sure the HTML and the PDF are in the same folder on the server.

The actual message passing system is pretty simple. The code in this example is about as simple as it gets. It either works or it doesn't, depending on the environment.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
Thanks for the reply.

The example you mentioned above is working fine in my browsers (IE7 and Mozilla firefox).

I tried to open that PDF in Adobe Live Cycle Designer ES 8.2 - it commented out the script present in the PDF and it showed up a message saying 'Needs an upgrade for the existing script'.

I am guessing like the script present in the PDF is not compatible with adobe acrobat 9 pro version?

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
The compatibilty of the script with Acrobat has nothing to with LiveCycle Designer. The script will work with Acrobat 9.

LiveCycle designer is a completely separate tool that creates XFA Forms. The format and scripting model of XFAs does not allow for Document Level Scripts (the location where the HostContainer is setup). When you do a conversion from an Acrobat Form into an XFA Form, and LiveCycle detects scripts, it displays this message.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

pavankumarreddyr
Registered: Dec 8 2008
Posts: 18
I saw the PDF that you are mentioning below - for this PDF i am able to add or edit the scripts at document level.

I am using Adobe Acrobat 9 Pro.

i.e.
Advanced -> Document Processing -> Edit All JavaScripts, Document Scripts submenu items are enabled for this PDF.But for my PDF which i created using Adobe Live Cycle Designer 8.2, the menu items :
Edit All JavaScripts & Document Scripts are disabled - which intern doesn't allow me to add or edit the document level scripts.Is there any reason for Edit All JavaScripts & Document Scripts submenus got disabled?How can i enable these menu items so that i can add document level scripts?

Is this related to any security restrictions? - i verified document restrictions summary for the PDF, except 'Change the document' and 'Document Assembly' remaining all are in 'Allowed' state.

Thanks in advance

R pavan kumar reddy

thomp
Expert
Registered: Feb 15 2006
Posts: 4411
A Live cycle document doesn't have any of the script locations that a PDF does. That's why these menu items are grayed out.

Read this blog:

http://www.acrobatusers.com/blogs/thomp/2007/08/07/so-what-is-the-difference-between-acroforms-and-xfa/

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

starsailor3k
Registered: Dec 15 2009
Posts: 4
>LiveCycle designer is a completely separate tool that creates XFA Forms. The format and scripting> >model of XFAs does not allow for Document Level Scripts (the location where the HostContainer is >setup). When you do a conversion from an Acrobat Form into an XFA Form, and LiveCycle detects >scripts, it displays this message.So there is no way to send messages to/from html page/embedded pdf if the pdf document is a XFA Form (created with LiveCycle Designer)?
In a document of windjack.com (Moving from acrobat to livecycle designer javascript) they say that is it possible to access 'standard' javascript' .
Thank you
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
Yes, you can pass messages between an XFA form and an HTML page. It's just a matter of where in the form the message handlers are setup. In an XFA form you need to put them in an event that is only called once when the PDF is opened. For example "DocReady".

The Standard, or AcroForm, scripting model is always there. It's an umbrella over all the other scripting models in Acrobat. The XFA scripting model does not replace it. The XFA scripting model is availible to XFA forms in adition to the AcroForm model.

This does not mean you can write document level scripts for an XFA PDF. You can't. When developing an XFA form you have to use the scripting locations that are availible in the XFA model.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

starsailor3k
Registered: Dec 15 2009
Posts: 4
Hi Thom,
thanks for your reply.
I've tried first the "IE Browser/Acrobat intercommunication " sample and also the sample at http://support.adobe.com/devsup/devsup.nsf/docs/54352.htm with Firefox 3.5.5/IE8 and Reader 9.2 in Windows XP. So after checked the acroforms I've tried to do the porting in xfa but til now with poor results.
I wrote a simple form with just one button that send a message and a html page that display the result.
The problem is that I receive the error that there isn't the hostcontainer obj.
I've set up the messagehandlers in the docReady as you told me (do I need to do this setup also if I want only to send messages?), this is the code for the form:

form1::ready:form - (JavaScript, client)

this.hostContainer.messageHandler =
{
onMessage: function(aMessage)
{
for(var i = 0; i < aMessage.length; i++)
console.println("Recv’d Msg[ " + i + "]: " + aMessage[i]);
},
onError: function(error, aMessage){ },
onDisclose: HostContainerDisclosurePolicy.SameOriginPolicy
};

form1.#subform[0].Button1::mouseUp - (JavaScript, client)


if ( !this.hostContainer )
app.alert( "No hostContainer obj" );
else {
var postArray = ["one","two"];
try {
this.hostContainer.postMessage( postArray );
}
catch ( e ) {
app.alert( "postMessage \ nError: " + e );
}
}

Then I've discovered that if I press '.' after 'this' in the list the hostContainer is not present, but the only document that I've found about compatibility between Xfa js and Acro js is for release 7 (before the introduction of hostContainer). I'm sure I've done a big mistake that I can't see. Any advice?
Thank you
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
From within XFA scripting context the keyword "this" refers to the current form element, not the document object, as it does from within an AcroForm document context. "hostContainer" is a property of the document object, it has nothing to do with XFA so LiveCycle doesn't know anything about it. To get to the document object from within the XFA context use "event.target".

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

starsailor3k
Registered: Dec 15 2009
Posts: 4
Thanks again Thom,
I've changed the code like you said and now the html receive the messages correctly.
The problems is (like you wrote in a previous post) with the environment. In windows xp works with ie8 and not with firefox 3.5 (after the button click nothing happens). In Vista Business 64 with Firefox 3.0 and Opera nothing happens, IE8 doesn't open any kind of embedded pdf and the only one ok is Chrome! Now I'm going to test under Ubuntu. Under mac if the js api is updated it's not implemented.
Do you know if exist a sort of 'compatibility matrix' between hostContainer and browsers and which are the security settings that can block this functionality?

Thanks in advance.
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
A complatibility matrix would be nice but I've never seen such a thing. The hostContainer is not what you would call a strongly supported feature. Partly this is because the browser functionality is so varied. You never know what new release or OS change is create a problem. So any matrix would be quickly out of date.

Thom Parker
The source for PDF Scripting Info
[url=http://www.pdfScripting.com]pdfscripting.com[/url]

The Acrobat JavaScript Reference, Use it Early and Often
[url=http://www.adobe.com/devnet/acrobat/javascript.php]http://www.adobe.com/devnet/acrobat/javascript.php[/url]

Then most important JavaScript Development tool in Acrobat
[url=http://www.pdfscripting.com/public/34.cfm#JSIntro][b]The Console Window (Video tutorial)[/b][/url]
[url=http://www.acrobatusers.com/tutorials/2006/javascript_console][b]The Console Window(article)[/b][/url]

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script