Iterator<COSObjectable> widgetIter = widgets.iterator();
while (widgetIter.hasNext())
{
COSObjectable next = widgetIter.next();
PDField field = null;
PDAnnotationWidget widget;
if (next instanceof PDField)
{
field = (PDField) next;
widget = field.getWidget();
}
else
{
widget = (PDAnnotationWidget) next;
}
PDFormFieldAdditionalActions actions = null;
if (field != null)
{
actions = field.getActions();
}
if (actions != null && actions.getF() != null
&& widget.getDictionary().getDictionaryObject(COSName.AP) == null)
{
// do nothing because the field will be formatted by acrobat
// when it is opened. See FreedomExpressions.pdf for an example of this.
}
else
{
PDAppearanceDictionary appearance = widget.getAppearance();
if (appearance == null)
{
appearance = new PDAppearanceDictionary();
widget.setAppearance(appearance);
}
PDAppearanceEntry normalAppearance = appearance.getNormalAppearance();
// TODO support more than one appearance stream
PDAppearanceStream appearanceStream =
normalAppearance.isStream() ? normalAppearance.getAppearanceStream() : null;
if (appearanceStream == null)
{
COSStream cosStream = acroForm.getDocument().getDocument().createCOSStream();
appearanceStream = new PDAppearanceStream(cosStream);
appearanceStream.setBBox(widget.getRectangle()
.createRetranslatedRectangle());
appearance.setNormalAppearance(appearanceStream);
}
List<Object> tokens = getStreamTokens(appearanceStream);