Embedding Video in PDF files using the Datalogics PDF Java Toolkit

Sample of the Week:

Judicious use of video in a PDF document can make the text far easier to understand and is a great way to distribute transcripts along with the video content itself. Adobe Acrobat and some other PDF authoring tools allow end users to embed video in a PDF document. This article discusses how to use the Datalogics PDF Java Toolkit to add video to a PDF in much the same way as Acrobat.

What You Need to Know First:
When you use Adobe Acrobat to add a movie to a PDF page, you aren’t exactly adding the movie directly to the page; Acrobat attached the movie you select plus a few other files that get installed on your drive along with Acrobat. After selecting the movie tool, Acrobat presents a dialog that let’s you select the movie file and set some options. What Acrobat then does is create a RichMedia Annotation then embeds a Flash movie player SWF file, a Flash video controller SWF file, and then the movie file itself. Acrobat automatically constructs the correct set of FlashVars to tell the video player what to play and how based on your selections in the dialog.

A video player and controller are supplied as input files with this Gist along with a public domain H.264 file. You’ll need these input files to run the Gist. The path to save them to is in the code.

Because the supplied video player is based on the one that is distributed with Adobe Acrobat, it uses the same parameters and JavaScript callbacks so it is interoperable with Acrobat. The only significant difference is that it will overlay the Datalogics logo on the video. However, you can easily substitute your own video player.

Embedding the Video:
We need to start by reading in the three files that we will need to create the assets that are attached to the PDFAnnotationRichMedia Object. We need to get the files from the way they are stored on the drive to an object that can be stored in a PDF.

Once we have the files set as PDFEmbeddedFile Objects, we can add them to a list of PDFNamedEmbeddedFiles and then the viewer can reference them by name.

With the files embedded, we can set up a configuration list that instructs the viewer which of the embedded files are to be used for which purposes.

Finally, we can tell the annotation when to activate and deactivate by creating a settings dictionary.

To get started with video in PDF files, download this Gist, it’s input files which are also in the Gist, and evaluation copy of The Datalogics PDF Java Toolkit.

Share this post with your friends

Get instant access to the latest PDF news, tips and tricks!

Do you want monthly updates on the latest document technology trends?

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time. 

Like what you're reading?

Get Datalogics blogs sent right to your inbox!

By submitting the form, you agree to receive marketing emails from Datalogics. You may unsubscribe at any time.