@@ -873,16 +873,16 @@ def append_pages_from_reader(
873
873
def _update_field_annotation (
874
874
self ,
875
875
field : DictionaryObject ,
876
- anno : DictionaryObject ,
876
+ annotation : DictionaryObject ,
877
877
font_name : str = "" ,
878
878
font_size : float = - 1 ,
879
879
) -> None :
880
880
# Calculate rectangle dimensions
881
- _rct = cast (RectangleObject , anno [AA .Rect ])
881
+ _rct = cast (RectangleObject , annotation [AA .Rect ])
882
882
rct = RectangleObject ((0 , 0 , abs (_rct [2 ] - _rct [0 ]), abs (_rct [3 ] - _rct [1 ])))
883
883
884
884
# Extract font information
885
- da = anno .get_inherited (
885
+ da = annotation .get_inherited (
886
886
AA .DA ,
887
887
cast (DictionaryObject , self .root_object [CatalogDictionary .ACRO_FORM ]).get (
888
888
AA .DA , None
@@ -917,7 +917,7 @@ def _update_field_annotation(
917
917
DictionaryObject ,
918
918
cast (
919
919
DictionaryObject ,
920
- anno .get_inherited (
920
+ annotation .get_inherited (
921
921
"/DR" ,
922
922
cast (
923
923
DictionaryObject , self .root_object [CatalogDictionary .ACRO_FORM ]
@@ -942,7 +942,7 @@ def _update_field_annotation(
942
942
font_subtype , _ , font_encoding , font_map = build_char_map_from_dict (
943
943
200 , font_res
944
944
)
945
- try : # get rid of width stored in -1 key
945
+ try : # remove width stored in -1 key
946
946
del font_map [- 1 ]
947
947
except KeyError :
948
948
pass
@@ -963,14 +963,14 @@ def _update_field_annotation(
963
963
# Retrieve field text and selected values
964
964
field_flags = field .get (FA .Ff , 0 )
965
965
if field .get (FA .FT , "/Tx" ) == "/Ch" and field_flags & FA .FfBits .Combo == 0 :
966
- txt = "\n " .join (anno .get_inherited (FA .Opt , []))
966
+ txt = "\n " .join (annotation .get_inherited (FA .Opt , []))
967
967
sel = field .get ("/V" , [])
968
968
if not isinstance (sel , list ):
969
969
sel = [sel ]
970
970
else : # /Tx
971
971
txt = field .get ("/V" , "" )
972
972
sel = []
973
- # Escape parentheses (pdf 1.7 reference, table 3.2 Literal Strings)
973
+ # Escape parentheses (PDF 1.7 reference, table 3.2, Literal Strings)
974
974
txt = txt .replace ("\\ " , "\\ \\ " ).replace ("(" , r"\(" ).replace (")" , r"\)" )
975
975
# Generate appearance stream
976
976
ap_stream = generate_appearance_stream (
@@ -987,8 +987,8 @@ def _update_field_annotation(
987
987
"/Length" : 0 ,
988
988
}
989
989
)
990
- if AA .AP in anno :
991
- for k , v in cast (DictionaryObject , anno [AA .AP ]).get ("/N" , {}).items ():
990
+ if AA .AP in annotation :
991
+ for k , v in cast (DictionaryObject , annotation [AA .AP ]).get ("/N" , {}).items ():
992
992
if k not in {"/BBox" , "/Length" , "/Subtype" , "/Type" , "/Filter" }:
993
993
dct [k ] = v
994
994
@@ -1005,16 +1005,16 @@ def _update_field_annotation(
1005
1005
)
1006
1006
}
1007
1007
)
1008
- if AA .AP not in anno :
1009
- anno [NameObject (AA .AP )] = DictionaryObject (
1008
+ if AA .AP not in annotation :
1009
+ annotation [NameObject (AA .AP )] = DictionaryObject (
1010
1010
{NameObject ("/N" ): self ._add_object (dct )}
1011
1011
)
1012
- elif "/N" not in cast (DictionaryObject , anno [AA .AP ]):
1013
- cast (DictionaryObject , anno [NameObject (AA .AP )])[
1012
+ elif "/N" not in cast (DictionaryObject , annotation [AA .AP ]):
1013
+ cast (DictionaryObject , annotation [NameObject (AA .AP )])[
1014
1014
NameObject ("/N" )
1015
1015
] = self ._add_object (dct )
1016
1016
else : # [/AP][/N] exists
1017
- n = anno [AA .AP ]["/N" ].indirect_reference .idnum # type: ignore
1017
+ n = annotation [AA .AP ]["/N" ].indirect_reference .idnum # type: ignore
1018
1018
self ._objects [n - 1 ] = dct
1019
1019
dct .indirect_reference = IndirectObject (n , 0 , self )
1020
1020
@@ -1071,61 +1071,60 @@ def update_page_form_field_values(
1071
1071
if PG .ANNOTS not in page :
1072
1072
logger_warning ("No fields to update on this page" , __name__ )
1073
1073
return
1074
- for writer_annot in page [PG .ANNOTS ]: # type: ignore
1075
- writer_annot = cast (DictionaryObject , writer_annot .get_object ())
1076
- if writer_annot .get ("/Subtype" , "" ) != "/Widget" :
1074
+ for annotation in page [PG .ANNOTS ]: # type: ignore
1075
+ annotation = cast (DictionaryObject , annotation .get_object ())
1076
+ if annotation .get ("/Subtype" , "" ) != "/Widget" :
1077
1077
continue
1078
- if "/FT" in writer_annot and "/T" in writer_annot :
1079
- writer_parent_annot = writer_annot
1078
+ if "/FT" in annotation and "/T" in annotation :
1079
+ parent_annotation = annotation
1080
1080
else :
1081
- writer_parent_annot = writer_annot .get (
1081
+ parent_annotation = annotation .get (
1082
1082
PG .PARENT , DictionaryObject ()
1083
1083
).get_object ()
1084
1084
1085
1085
for field , value in fields .items ():
1086
1086
if not (
1087
- self ._get_qualified_field_name (writer_parent_annot ) == field
1088
- or writer_parent_annot .get ("/T" , None ) == field
1087
+ self ._get_qualified_field_name (parent_annotation ) == field
1088
+ or parent_annotation .get ("/T" , None ) == field
1089
1089
):
1090
1090
continue
1091
1091
if (
1092
- writer_parent_annot .get ("/FT" , None ) == "/Ch"
1093
- and "/I" in writer_parent_annot
1092
+ parent_annotation .get ("/FT" , None ) == "/Ch"
1093
+ and "/I" in parent_annotation
1094
1094
):
1095
- del writer_parent_annot ["/I" ]
1095
+ del parent_annotation ["/I" ]
1096
1096
if flags :
1097
- writer_annot [NameObject (FA .Ff )] = NumberObject (flags )
1097
+ annotation [NameObject (FA .Ff )] = NumberObject (flags )
1098
1098
if isinstance (value , list ):
1099
1099
lst = ArrayObject (TextStringObject (v ) for v in value )
1100
- writer_parent_annot [NameObject (FA .V )] = lst
1100
+ parent_annotation [NameObject (FA .V )] = lst
1101
1101
elif isinstance (value , tuple ):
1102
- writer_annot [NameObject (FA .V )] = TextStringObject (
1102
+ annotation [NameObject (FA .V )] = TextStringObject (
1103
1103
value [0 ],
1104
1104
)
1105
1105
else :
1106
- writer_parent_annot [NameObject (FA .V )] = TextStringObject (value )
1107
- if writer_parent_annot .get (FA .FT ) in ("/Btn" ):
1108
- # case of Checkbox button (no /FT found in Radio widgets
1106
+ parent_annotation [NameObject (FA .V )] = TextStringObject (value )
1107
+ if parent_annotation .get (FA .FT ) in ("/Btn" ):
1108
+ # Checkbox button (no /FT found in Radio widgets)
1109
1109
v = NameObject (value )
1110
- if v not in writer_annot [NameObject (AA .AP )][NameObject ("/N" )]:
1110
+ if v not in annotation [NameObject (AA .AP )][NameObject ("/N" )]:
1111
1111
v = NameObject ("/Off" )
1112
1112
# other cases will be updated through the for loop
1113
- writer_annot [NameObject (AA .AS )] = v
1113
+ annotation [NameObject (AA .AS )] = v
1114
1114
elif (
1115
- writer_parent_annot .get (FA .FT ) == "/Tx"
1116
- or writer_parent_annot .get (FA .FT ) == "/Ch"
1115
+ parent_annotation .get (FA .FT ) == "/Tx"
1116
+ or parent_annotation .get (FA .FT ) == "/Ch"
1117
1117
):
1118
1118
# textbox
1119
1119
if isinstance (value , tuple ):
1120
1120
self ._update_field_annotation (
1121
- writer_parent_annot , writer_annot , value [1 ], value [2 ]
1121
+ parent_annotation , annotation , value [1 ], value [2 ]
1122
1122
)
1123
1123
else :
1124
- self ._update_field_annotation (writer_parent_annot , writer_annot )
1124
+ self ._update_field_annotation (parent_annotation , annotation )
1125
1125
elif (
1126
- writer_annot .get (FA .FT ) == "/Sig"
1126
+ annotation .get (FA .FT ) == "/Sig"
1127
1127
): # deprecated # not implemented yet
1128
- # signature
1129
1128
logger_warning ("Signature forms not implemented yet" , __name__ )
1130
1129
1131
1130
def reattach_fields (
0 commit comments