From 9abcfc2bdb128eddf7ab43bec00d701c4cf894ec Mon Sep 17 00:00:00 2001 From: rdl Date: Wed, 25 Oct 2023 17:56:35 +0200 Subject: [PATCH] BUG: Error when filling a value with parentheses #2268 --- pypdf/_writer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 51b92b0e1..64cd9eb89 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -920,7 +920,8 @@ def _update_text_field(self, field: DictionaryObject) -> None: else: # /Tx txt = field.get("/V", "") sel = [] - + # Escape parentheses (Ref. 7.3.4.2 Literal Strings) + txt = txt.replace('(', r'\(').replace(')', r'\)') # Generate appearance stream ap_stream = f"q\n/Tx BMC \nq\n1 1 {rct.width - 1} {rct.height - 1} re\nW\nBT\n{da}\n".encode() for line_number, line in enumerate(txt.replace("\n", "\r").split("\r")):