@@ -798,16 +798,7 @@ private Map<COSDictionary,Set<COSDictionary>> buildPagesWidgetsMap(
798798 // If there is a widget with a missing page reference we need to build the map reverse i.e.
799799 // from the annotations to the widget.
800800 LOG .warn ("There has been a widget with a missing page reference, will check all page annotations" );
801- Set <COSDictionary > widgetDictionarySet = new HashSet <>();
802- for (PDField field : fields )
803- {
804- List <PDAnnotationWidget > widgets = field .getWidgets ();
805- for (PDAnnotationWidget widget : widgets )
806- {
807- widgetDictionarySet .add (widget .getCOSObject ());
808- }
809- }
810-
801+ Set <COSDictionary > widgetDictionarySet = createWidgetDictionarySet (fields );
811802 for (PDPage page : pages )
812803 {
813804 for (PDAnnotation annotation : page .getAnnotations ())
@@ -822,6 +813,26 @@ private Map<COSDictionary,Set<COSDictionary>> buildPagesWidgetsMap(
822813 return pagesAnnotationsMap ;
823814 }
824815
816+ /**
817+ * Return a set of all annotation widget dictionaries related to the fields to be flattened.
818+ *
819+ * @param fields
820+ * @return
821+ */
822+ private Set <COSDictionary > createWidgetDictionarySet (List <PDField > fields )
823+ {
824+ Set <COSDictionary > widgetDictionarySet = new HashSet <>();
825+ for (PDField field : fields )
826+ {
827+ List <PDAnnotationWidget > widgets = field .getWidgets ();
828+ for (PDAnnotationWidget widget : widgets )
829+ {
830+ widgetDictionarySet .add (widget .getCOSObject ());
831+ }
832+ }
833+ return widgetDictionarySet ;
834+ }
835+
825836 private void fillPagesAnnotationMap (Map <COSDictionary , Set <COSDictionary >> pagesAnnotationsMap ,
826837 PDPage page , PDAnnotationWidget widget )
827838 {
0 commit comments