@@ -978,14 +978,14 @@ def update_page_form_field_values(
978978 if PG .ANNOTS not in page :
979979 logger_warning ("No fields to update on this page" , __name__ )
980980 return
981- for annotation in page [PG .ANNOTS ]: # type: ignore
982- annotation_obj = cast (DictionaryObject , annotation .get_object ())
983- if annotation_obj .get ("/Subtype" , "" ) != "/Widget" :
981+ for annotation_ref in page [PG .ANNOTS ]: # type: ignore
982+ annotation = cast (DictionaryObject , annotation_ref .get_object ())
983+ if annotation .get ("/Subtype" , "" ) != "/Widget" :
984984 continue
985- if "/FT" in annotation_obj and "/T" in annotation_obj :
986- parent_annotation = annotation_obj
985+ if "/FT" in annotation and "/T" in annotation :
986+ parent_annotation = annotation
987987 else :
988- parent_annotation = annotation_obj .get (
988+ parent_annotation = annotation .get (
989989 PG .PARENT , DictionaryObject ()
990990 ).get_object ()
991991
@@ -1003,7 +1003,6 @@ def update_page_form_field_values(
10031003 del parent_annotation ["/I" ]
10041004 if flags :
10051005 annotation [NameObject (FA .Ff )] = NumberObject (flags )
1006- # Set the field value
10071006 if not (value is None and flatten ): # Only change values if given by user and not flattening.
10081007 if isinstance (value , list ):
10091008 lst = ArrayObject (TextStringObject (v ) for v in value )
@@ -1025,9 +1024,14 @@ def update_page_form_field_values(
10251024 if v not in normal_ap :
10261025 v = NameObject ("/Off" )
10271026 appearance_stream_obj = normal_ap .get (v )
1028- # Other cases will be updated through the for loop
1027+ # other cases will be updated through the for loop
10291028 annotation [NameObject (AA .AS )] = v
10301029 annotation [NameObject (FA .V )] = v
1030+ if flatten and appearance_stream_obj is not None :
1031+ # We basically copy the entire appearance stream, which should be an XObject that
1032+ # is already registered. No need to add font resources.
1033+ rct = cast (RectangleObject , annotation [AA .Rect ])
1034+ self ._add_apstream_object (page , appearance_stream_obj , field , rct [0 ], rct [1 ])
10311035 elif (
10321036 parent_annotation .get (FA .FT ) == "/Tx"
10331037 or parent_annotation .get (FA .FT ) == "/Ch"
@@ -1046,7 +1050,7 @@ def update_page_form_field_values(
10461050 annotation [NameObject (AA .AP )] = DictionaryObject (
10471051 {NameObject ("/N" ): self ._add_object (appearance_stream_obj )}
10481052 )
1049- elif "/N" not in (ap := cast (DictionaryObject , annotation [AA .AP ])):
1053+ elif "/N" not in (ap := cast (DictionaryObject , annotation [AA .AP ])):
10501054 cast (DictionaryObject , annotation [NameObject (AA .AP )])[
10511055 NameObject ("/N" )
10521056 ] = self ._add_object (appearance_stream_obj )
0 commit comments