Hide and Show Rich Media in PDF Files

| 3 Comments

I’ve been getting a lot of questions lately from developers who want to use the new Rich Media Annotations (RMA) in their PDF files but are having trouble migrating from the legacy MediaPlayer objects. The main problem is that they want to be able to toggle the visibility of an RMA but can’t; RMAs don’t have a "visibility" property like the MediaPlayer object does.

Before I discuss the work-around for the visibility issue, I’d like to take a moment for a "public service announcement". Here goes…

Whereever possible, start using the Rich Media Annotations instead of the legacy MediaPlayer object. The MediaPlayer object relies on external players like Windows Media Player, QuickTime and the Flash Player to play the various types of media. This means that you are relying on the right player for your type of media to be installed on the client machine in order for your PDF file to work properly.

Rich Media Annotations rely on the Flash Player in Acrobat. This means that you can always be sure that the media will play properly and you won’t get security warnings since the player is built into Acrobat and Reader.

Now – back to our regularly scheduled program.

The trick to toggling the visibility of an RMA even without a visibility property is to put it on a layer and then toggle the visibility of the layer.

Huh? You can’t do that in Acrobat!

Yes you can… with Thom Parker’s "OCG (Layers) Tool". The OCG (Layers) Tool is an Acrobat Plug-in for creating, configuring, and attaching page content to Optional Content Groups, also called Layers. OCGs can be used to control the visibility of visual content (text, graphics and other objects) on a PDF page.

Because an active RMA is always visible, you’ll need to deactivate it before toggling the visibility of the layer. Take a look at the scripts in the buttons of the example PDF linked to below.

The OCG (Layers) Tool is available for free with your premium subscription to pdfscripting.com. This tool alone is worth the price of admission but there’s about 18 other great tools up there as well as tutorials, copy-and-paste scripts and more.

Example of Hide and Show Rich Media using Layer visibility