Skip to content

Commit

Permalink
BUG: Updated pdf fields don't show up when page is written (#412)
Browse files Browse the repository at this point in the history
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 <tomiademidun@gmail.com>
  • Loading branch information
mwhit74 and ademidun committed Apr 17, 2022
1 parent 9cd16d0 commit f92e975
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit f92e975

Please sign in to comment.