Actions in Action at Adobe

| 1 Comment

The new Actions Wizard in Adobe Acrobat X can be leveraged to automate repetitive tasks. One such task is the ability to add document level JavaScript and set actions on objects in a PDF document. Basically, you can write an Action to automate the addition of complex interactivity that would otherwise be tedious and prone to human error.

At Adobe we’ve actually leveraged this capability to enable one of our partners to create Dynamic PDF files for our customer success stories. Almost all of the work takes place in InDesign where they’re most comfortable. The final step happens in Acrobat; they simply run an Action that I developed for them. Seconds later, the job is complete.The Video Player Plus, which is identical to the standard video player that ships with Acrobat 9 and X except for the few additional functions that I added was also used for this project. You’ll see why when I go over the design goals for our dynamic customer success story project.


DefaultLinear.pngMany of our customer success stories, which are typically 2-4 page PDF documents, have videos associated with them that reside on Adobe TV and are linked to from the PDF file. This arrangement has worked well but we’ve been toying with the idea of embedding the videos in the PDF files since we released Acrobat 9. The problem was that PDF files with embedded video can get very large very fast. We did have the ability to stream the video into the document but then the user would need to be online and with a fairly robust connection to be able to experience the file in the way we intended. Finally, we could have used the Video Player Plus which I posted over a year ago, to embed a low resolution version and stream an HD version of the video but using it involved some hand tweaking of far too many settings in the PDF file (using Acrobat) to be practical for the typical InDesign user. Finally, not everyone is using the latest readers and some may not even be using an Adobe viewer to read PDF files. We needed to accommodate these users too.

Design Goals:

With all of the above in mind, we came up with the following design goals. These are roughly in order of importance.

  • The PDF file had to be a practical demonstration of how dynamic a PDF document could be. We wanted to show off the technology and inspire our customers.
  • The PDF file would need to provide a good experience if the user was offline and a great experience when the user was online.
  • The final PDF file had to be small enough to email. Under 10Mb would be acceptable, under 5Mb was the target.
  • Because these documents go through many revision cycles, the authoring process had to be geared towards the user of InDesign and minimize the amount of post processing in Acrobat. The process had to be easily repeatable by users who have very little experience with the advanced functionality of Acrobat.
  • Given that the dynamic nature of the file would only work in version 9 or higher, we had to create the file in such a way that users of other PDF tools would be informed that they may not be experiencing the file in the way we intended.

Given all these criteria, specifically that 4th bullet, this project would have been impossible without the use of Actions in Acrobat X.

Take a look at these two examples to see what we finally came up with and then continue reading to see how we did it.

DIVIDI Customer Success Story

Hassell Customer Success Story

Go to the second page of each document. Notice the button roll-overs. Clicking the first play button will play the embedded video, clicking the play HD button will stream in an HD version of the video.

Engineering the Solution:

The video player that ships with Acrobat 9 and X can play either an embedded video or a video streaming from the web. For this project we needed a player that could do both. Back in the Acrobat 9 days, I created the Video Player Plus which allows for the same video widget in a PDF file to play any number of embedded videos and any number of videos streamed from the web. After my modifications to the default player, the Video Player Plus has the ability to programmatically change the source of the video playing in the video widget as well as store the original source for reference.

In terms of accommodating users who are using non-Adobe PDF tools, we can actually take advantage of the fact that they typically don’t have a full JavaScript implementation and don’t typically handle layers as well as Acrobat. Top level layers created in InDesign export to PDF perfectly with their names and visibility settings in tact. InDesign can also place video files, create “posters” for the video and assign player bar properties as well as create buttons complete with roll over states and actions; all of this exports perfectly as well. By creating a template for the customer success stories in InDesign that uses standardized layer and button naming conventions, we can then use JavaScript in Acrobat to “activate” these elements and hide or show them as needed.

So far, only Acrobat and Reader can programmatically hide a layer. To present a “warning” to a user that has a non-Adobe viewer, like the Preview application on a Mac, you simply create a layer in InDesign with the warning. You then add JavaScript to the file that lets Acrobat and Reader hide the layer; other software will always display the layer. All that’s left is to find a good place to put the warning so that the user will still be able to read the content even if the interactivity isn’t functional.

Finally, we need a way to make all of this work in a streamlined and repeatable way.

One of the most powerful Acrobat JavaScript features is the ability for it to actually add code to various objects in a PDF file. A JavaScript can add JavaScript at the document level as well as buttons, links and bookmarks. Additionally, one of the steps in an Action is to Execute JavaScript. Actions can also be easily shared, simply export the Action, send it to someone else and they simply open the file to install the Action into their copy of Acrobat X. By combining all of these capabilities, I found that I could easily and quite literally transfer the benefits of my JavaScript expertise to someone else who doesn’t know anything about code. Think about that for a minute.

Integrating the new video player with InDesign:
InDesign ships with the same exact default video player as Acrobat 9 and X so it can export PDF files that work with Reader and Acrobat. This means that I could simply replace the default InDesign video player with the Video Player Plus and InDesign wouldn’t know the difference. Since I only added functionality and didn’t change any existing code in the player, InDesign would continue to be able to use this new player to create proper PDF files.

Managing Objects through JavaScript:
Acrobat JavaScript is extremely powerful but it does have it’s idiosyncrasies. For example you can get the value of a field directly as long as you know the name of it. The code below will set variable v to the value of the field named myText.

var v = this.getField(“myText”).value

This is because the value of myText is the same no matter what page myText is on. myText can even be present on multiple pages, each one with the same value. Buttons are also considered fields in Acrobat so you can get access to a button’s properties as long as you know the name of the button.

With layers, it’s not so simple. Different pages can have different numbers of layers and these layers can have the same name but be completely unrelated. Nevertheless, if you want to programmatically control the visibility of a layer you need to know it’s name, just like a field, but you also need to know what page it’s on.

Basically, if you want to be able to programmatically control an object in Acrobat you need to know it’s name. This discussion is really just a long way of saying that if you want to use an Action to add JavaScript to a PDF file and have it work properly, you need to know the name of every object that you want the script to modify. This means you need to start with a well defined template in InDesign with a predefined set of layer and button names.

Next week, I’ll be posting the InDesign template, instructions for use and the Action to you can try this out at home.