Understanding the PDF file format – interactive elements

One of the really useful features of the PDF file format is the ability to have interactive elements. These began as just simple checkboxes, buttons, comboboxes and textfields type widgets and the list has expanded to include the ability to embed Sounds, Movies and even other files or URLs. This makes the PDF file format a very interactive medium.

Here is one of my favorite examples:

All of these interactive features can be defined in 2 ways. Firstly, they can exist in  as PDF objects defined within the PDF file and they inherit values from their parent objects. This is the original FDF version. It uses the standard PDF Cos format and would look something like this

26 0 obj
<<
/F 4
/I[1]
/Type/Annot
/Rect[196 594 314 613]
/BS<</W 1/S/U>>
/FT/Ch/
Subtype/Widget
/P 24 0 R
/T(Item)
/V(Soft Taco)
/AP<</N 142 0 R>>
/Ff 393216
/MK<</BC[0 0 0]>>
/Opt[(Burrito)(Soft Taco)(Mexico City)(Quesadilla)(Taquitaco)]
/DA(/TiRo 0 Tf 0 0 1 rg)
>>endobj

Or they can appear in one of several XML structures inside the file. Here is an example – the actual XML is buried inside streams in the referenced objects.

<<
/XFA[(preamble)40 0 R
(config)41 0 R
(template)42 0 R

You can also define as both a Cos object with data in the XFA – the spec is nothing if not flexible!

(datasets)43 0 R
(localeSet)44 0 R
(postamble)45 0 R]

Forms can also be linked to events and to Javascript code inside the PDF and can have tooltips, change their visibilty and interact with other components. They can also reference widgets on other pages. So there is not much you cannot achieve with them…

The thing that I found most confusing when starting was that interactive elements can actually be referenced in 2 separate ways. A PDF document can have a single Acroform or XFA object (which lists all the widgets in the document), but each page can also have a Annots object which lists the widgets on that page. So you need to potentially look at both lists and then workout which are used on any page.

So if you think PDF files are about just static WYSIWYG documents, you have been missing a whole dimension. Give them a try.

This post is part of our “Understanding the PDF File Format” series. In each article, we aim to take a specific PDF feature and explain it in simple terms. If you wish to learn more about PDF, we have 13 years worth of PDF knowledge and tips, so click here to visit our series index!

Related Posts:

The following two tabs change content below.

Mark Stephens

System Architect and Lead Developer at IDRSolutions
Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX. He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.
Markee174

About Mark Stephens

Mark Stephens has been working with Java and PDF since 1999 and has diversified into HTML5, SVG and JavaFX.

He also enjoys speaking at conferences and has been a Speaker at user groups, Business of Software, Seybold and JavaOne conferences. He has a very dry sense of humor and an MA in Medieval History for which he has not yet found a practical use.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>