Javascript with 3D (U3D) image

Can I have a sample code on attaching Javascript to an 3D annotation?

You may want to take a look at the following FAQ entry:

“How do I embed JavaScript inside a PDF?”

Using the same approach you can embed JavaScript under AA (i.e.
Additional Actions) key in the U3D annotation dictionary.

Some of our customers found that using CosEdit utility
( was helpful in similar situations. You could
use this utility to examine the structure of the existing PDF documents
with U3D annotations. You can also compare your documents against the
files with correct JavaScript actions.

For example, one of our customers reported that there is an
undocumented key (AP) for storing 3D model animation settings. For

// In C++
Obj* an_dict = doc.CreateIndirectDict(); u3d_data_dict->Put("AN",
an_dict); an_dict->Put("PC", new Number(-1)); an_dict->Put("Subtype",
new Name("Linear")); an_dict->Put("TM", new Number(1));
an_dict->Put("Type", new Name("3DAnimationStyle"));

The "AN" key is not documented in the PDF reference 1.6.