From 82cdca07232178734b094a9a50d637fbe5aadfae Mon Sep 17 00:00:00 2001 From: rdl Date: Thu, 26 Oct 2023 09:15:51 +0200 Subject: [PATCH] Add suggestion from pubpub-zz --- pypdf/_writer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 64cd9eb89..8f4767415 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -920,8 +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'\)') + # Escape parentheses (pdf 1.7 reference, table 3.2 Literal Strings) + txt = txt.replace("\\", "\\\\").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")):