Acrobat 9 is shipping and Here is how to communicate between PDF and Flash/Flex

Prior Acrobat 9, we were able to communicate between a PDF and a Flash/Flex application residing in the same browser window (e.g. the iframe approach). Acrobat 9 introduces a new feature called Rich Media Annotation that allows you to amazing stuff with Flash … one of them being the ability to embed Flash into a PDF and communicate with it via JavaScript. The example here is simple PDF document with an embedded Flex application that takes a product ID from the PDF and queries Amazon Web Services for product information (features, price, release date etc.).

In addition to the Flash playback support, Acrobat/Reader 9 can communicate with embedded SWF by utilizing the ExternalInterface API. This means that you must register your ActionScript function to indicate that it should be made available to the PDF by using the addCallBack() method as follows:

/* ActionScript */
// Register an ActionScript method as callable from the container
ExternalInterface.addCallback("find", find);

// Find a product
public function find(itemId:String):void

On the PDF side, all you need to do is to get hold of the Flash object and call into the ActionScript method by using the callAS( methodName:String, <argument1, argument2, and so on…>) as follows:

/* JavaScript */

// Get hold of the first Flash object on the first page
var annot = getAnnotsRichMedia(0)[0];

if ( annot )
// if exists, call the function called "find"
// and pass an item ID as an argument
annot.callAS( "find", "B000NDIB6Y");

Again, what the callAS method does is calling into ActionScript via ExternalInterface calling convention to an exposed method. The example I mentioned in this post can be downloaded here. Acrobat/Reader 9 is required. If you want to reuse the Flex application, you will need to register for an Amazon Web Services and their Associates accounts.


How-to Steps:

  1. Create a blank PDF or open an existing one in Acrobat 9.
  2. Add a button by going into the form editing mode.

    Form Editing

  3. Add a Run Javascript action to the button.

    Run JavaScript Action

  4. Add the Flex SWF to the PDf by using the Flash tool.

    Flash tool

  5. Editing the Flash properties to make it start as soon as the PDF is opened.

    Flash properties

  6. Save the PDF and the end result should look similar to this.