{
if(reference == null)
return null;
PdfDictionary dataObject = (PdfDictionary)reference.getDataObject();
PdfName fieldType = (PdfName)dataObject.get(PdfName.FT);
PdfInteger fieldFlags = (PdfInteger)dataObject.get(PdfName.Ff);
int fieldFlagsValue = (fieldFlags == null ? 0 : fieldFlags.getRawValue());
if(fieldType.equals(PdfName.Btn)) // Button.
{
if((fieldFlagsValue & FlagsEnum.Pushbutton.getCode()) > 0) // Pushbutton.
return new PushButton(reference);
else if((fieldFlagsValue & FlagsEnum.Radio.getCode()) > 0) // Radio.
return new RadioButton(reference);
else // Check box.
return new CheckBox(reference);
}
else if(fieldType.equals(PdfName.Tx)) // Text.
return new TextField(reference);
else if(fieldType.equals(PdfName.Ch)) // Choice.
{
if((fieldFlagsValue & FlagsEnum.Combo.getCode()) > 0) // Combo box.
return new ComboBox(reference);
else // List box.
return new ListBox(reference);
}
else if(fieldType.equals(PdfName.Sig)) // Signature.
return new SignatureField(reference);
else // Unknown.
throw new UnsupportedOperationException("Unknown field type: " + fieldType);
}