How do I create a widget annotation with a date picker?

Q: I want to create a widget annotation (like a text annotation) where readers like Adobe will display a date picker. How can I programmatically create one?

A: You can create one by embedding JS actions to the widget that will tell readers like Adobe Reader to display the picker:

TextWidget text3 = TextWidget.Create(doc, new Rect(110, 660, 380, 690), "date.picker");
Action dateAction = Action.CreateJavaScript(doc, "AFDate_FormatEx(\"d/m/yy\");"); // change date format here
Obj aaObj = text3.GetSDFObj().PutDict("AA");
aaObj.Put("K", dateAction.GetSDFObj());
aaObj.Put("F", dateAction.GetSDFObj());


Take a look at the interactive forms sample for more details.