)
{
PdfDataObject baseDataObject = getBaseDataObject();
if(baseDataObject instanceof PdfDictionary) // Merged annotation.
{
PdfArray widgetsArray = new PdfArray();
{
PdfDictionary fieldDictionary = (PdfDictionary)baseDataObject;
PdfDictionary widgetDictionary = null;
// Extracting widget entries from the field...
for(PdfName key : new HashMap<PdfName,PdfDirectObject>(fieldDictionary).keySet())
{
// Is it a widget entry?
if(key.equals(PdfName.Type)
|| key.equals(PdfName.Subtype)
|| key.equals(PdfName.Rect)
|| key.equals(PdfName.Contents)
|| key.equals(PdfName.P)
|| key.equals(PdfName.NM)
|| key.equals(PdfName.M)
|| key.equals(PdfName.F)
|| key.equals(PdfName.BS)
|| key.equals(PdfName.AP)
|| key.equals(PdfName.AS)
|| key.equals(PdfName.Border)
|| key.equals(PdfName.C)
|| key.equals(PdfName.A)
|| key.equals(PdfName.AA)
|| key.equals(PdfName.StructParent)
|| key.equals(PdfName.OC)
|| key.equals(PdfName.H)
|| key.equals(PdfName.MK))
{
if(widgetDictionary == null)
{
widgetDictionary = new PdfDictionary();
PdfReference widgetReference = getFile().register(widgetDictionary);
// Remove the field from the page annotations (as the widget annotation is decoupled from it)!
PdfArray pageAnnotationsArray = (PdfArray)File.resolve(((PdfDictionary)File.resolve(fieldDictionary.get(PdfName.P))).get(PdfName.Annots));
pageAnnotationsArray.remove(field.getBaseObject());
// Add the widget to the page annotations!
pageAnnotationsArray.add(widgetReference);
// Add the widget to the field widgets!
widgetsArray.add(widgetReference);
// Associate the field to the widget!
widgetDictionary.put(PdfName.Parent,field.getBaseObject());
}