You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When PDF contain non-latin text (Thai in this case), pdf.output() fails to write pdf to a file with exception UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-11: ordinal not in range(256)
Error details
Traceback (most recent call last):
File "~/sandbox/fpdf-bug/main.py", line 16, in <module>
pdf.output(f"test_encrypt_utf8_fpdf_{__version__}.pdf")
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/fpdf.py", line 4784, in output
self.buffer = output_producer.bufferize()
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/output.py", line 443, in bufferize
pdf_obj.serialize(_security_handler=fpdf._security_handler)
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/syntax.py", line 172, in serialize
obj_dict = self._build_obj_dict(_security_handler)
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/syntax.py", line 193, in _build_obj_dict
return build_obj_dict(
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/syntax.py", line 244, in build_obj_dict
value = value.serialize(
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/syntax.py", line 277, in serialize
return _security_handler.encrypt_string(self, _obj_id)
File "~/sandbox/fpdf-bug/venv/lib/python3.10/site-packages/fpdf/encryption.py", line 215, in encrypt_string
return f"<{bytes(self.encrypt_bytes(string.encode('latin-1'), obj_id)).hex().upper()}>"
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-11: ordinal not in range(256)
Describe the bug
When PDF contain non-latin text (Thai in this case),
pdf.output()
fails to write pdf to a file with exceptionUnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-11: ordinal not in range(256)
Error details
Minimal code
Environment
Please provide the following information:
fpdf2
version used: tested on tag 2.7.0 and 2.7.5The text was updated successfully, but these errors were encountered: