From f92e97554a9a1c087fdec9667fd17fa53a52ab8f Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Apr 2022 10:03:45 -0600 Subject: [PATCH] BUG: Updated pdf fields don't show up when page is written (#412) Closes #355 See #300 Borrowed code from ademidun in the comment history and inserted it into the proper location in the pdf.py module. Co-authored-by: Tomiwa Ademidun --- PyPDF2/pdf.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index ec9b47235..d10418606 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -118,6 +118,7 @@ def __init__(self): }) self._root = None self._root_object = root + self.set_need_appearances_writer() def _addObject(self, obj): self._objects.append(obj) @@ -136,6 +137,23 @@ def _addPage(self, page, action): action(pages[PA.KIDS], page) pages[NameObject(PA.COUNT)] = NumberObject(pages[PA.COUNT] + 1) + def set_need_appearances_writer(self): + # See 12.7.2 and 7.7.2 for more information: + # http://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/PDF32000_2008.pdf + try: + catalog = self._root_object + # get the AcroForm tree + if "/AcroForm" not in catalog: + self._root_object.update({ + NameObject("/AcroForm"): IndirectObject(len(self._objects), + 0, self)}) + + need_appearances = NameObject("/NeedAppearances") + self._root_object["/AcroForm"][need_appearances] = BooleanObject(True) + + except Exception as e: + print('set_need_appearances_writer() catch : ', repr(e)) + def addPage(self, page): """ Adds a page to this PDF file. The page is usually acquired from a