@@ -831,7 +831,7 @@ def _get_qualified_field_name(self, parent: DictionaryObject) -> Optional[str]:
831
831
return qualified_parent + "." + cast (str , parent ["/T" ])
832
832
return cast (str , parent ["/T" ])
833
833
834
- def _update_text_field (self , field : DictionaryObject ) -> None :
834
+ def _update_text_field (self , field : DictionaryObject , encoding : Optional [ str ] = None ) -> None :
835
835
# Calculate rectangle dimensions
836
836
_rct = cast (RectangleObject , field [AA .Rect ])
837
837
rct = RectangleObject ((0 , 0 , _rct [2 ] - _rct [0 ], _rct [3 ] - _rct [1 ]))
@@ -859,21 +859,22 @@ def _update_text_field(self, field: DictionaryObject) -> None:
859
859
sel = []
860
860
861
861
# Generate appearance stream
862
- ap_stream = f"q\n /Tx BMC \n q\n 1 1 { rct .width - 1 } { rct .height - 1 } re\n W\n BT\n { da } \n " . encode ()
862
+ ap_stream = f"q\n /Tx BMC \n q\n 1 1 { rct .width - 1 } { rct .height - 1 } re\n W\n BT\n { da } \n "
863
863
for line_number , line in enumerate (txt .replace ("\n " , "\r " ).split ("\r " )):
864
864
if line in sel :
865
865
# may be improved but can not find how get fill working => replaced with lined box
866
866
ap_stream += (
867
867
f"1 { y_offset - (line_number * font_height * 1.4 ) - 1 } { rct .width - 2 } { font_height + 2 } re\n "
868
868
f"0.5 0.5 0.5 rg s\n { field [AA .DA ]} \n "
869
- ). encode ()
869
+ )
870
870
if line_number == 0 :
871
- ap_stream += f"2 { y_offset } Td\n " . encode ()
871
+ ap_stream += f"2 { y_offset } Td\n "
872
872
else :
873
873
# Td is a relative translation
874
- ap_stream += f"0 { - font_height * 1.4 } Td\n " .encode ()
875
- ap_stream += b"(" + str (line ).encode ("UTF-8" ) + b") Tj\n "
876
- ap_stream += b"ET\n Q\n EMC\n Q\n "
874
+ ap_stream += f"0 { - font_height * 1.4 } Td\n "
875
+ ap_stream += "(" + str (line ) + ") Tj\n "
876
+ ap_stream += "ET\n Q\n EMC\n Q\n "
877
+ ap_stream = ap_stream .encode (encoding ) if encoding is not None else ap_stream .encode ()
877
878
878
879
# Create appearance dictionary
879
880
dct = DecodedStreamObject .initialize_from_dictionary (
@@ -924,6 +925,7 @@ def update_page_form_field_values(
924
925
fields : Dict [str , Any ],
925
926
flags : FieldFlag = OPTIONAL_READ_WRITE_FIELD ,
926
927
auto_regenerate : Optional [bool ] = True ,
928
+ encoding : Optional [str ] = None
927
929
) -> None :
928
930
"""
929
931
Update the form field values for a given page from a fields dictionary.
@@ -992,7 +994,7 @@ def update_page_form_field_values(
992
994
if AA .DA in f :
993
995
da = f [AA .DA ]
994
996
writer_annot [NameObject (AA .DA )] = da
995
- self ._update_text_field (writer_annot )
997
+ self ._update_text_field (writer_annot , encoding )
996
998
elif writer_annot .get (FA .FT ) == "/Sig" :
997
999
# signature
998
1000
logger_warning ("Signature forms not implemented yet" , __name__ )
0 commit comments