Skip to content

Commit

Permalink
Add foced-encoding block back
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Jul 5, 2022
1 parent a832ef6 commit 1331711
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,7 +1897,15 @@ def create_string_object(
if isinstance(string, str):
return TextStringObject(string)
elif isinstance(string, bytes):
if isinstance(forced_encoding, str):
if isinstance(forced_encoding, (list, dict)):
out = ""
for x in string:
try:
out += forced_encoding[x]
except Exception:
out += bytes((x,)).decode("charmap")
return TextStringObject(out)
elif isinstance(forced_encoding, str):
if forced_encoding == "bytes":
return ByteStringObject(string)
return TextStringObject(string.decode(forced_encoding))
Expand Down

0 comments on commit 1331711

Please sign in to comment.