Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Linked Form Value Issue #398 #414

Merged
merged 5 commits into from
Apr 16, 2022
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def updatePageFormFieldValues(self, page, fields):
'''
Update the form field values for a given page from a fields dictionary.
Copy field texts and values from fields to page.
If the field links to a parent object, add the information to the parent.

:param page: Page reference from PDF writer where the annotations
and field data will be updated.
Expand All @@ -372,11 +373,18 @@ def updatePageFormFieldValues(self, page, fields):
# Iterate through pages, update field values
for j in range(0, len(page[PG.ANNOTS])):
writer_annot = page[PG.ANNOTS][j].getObject()
# retrieve parent field values, if present
if PG.PARENT in writer_annot:
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved
writer_parent_annot = page[PG.ANNOTS][j].getObject()[PG.PARENT]
MartinThoma marked this conversation as resolved.
Show resolved Hide resolved
for field in fields:
if writer_annot.get('/T') == field:
writer_annot.update({
NameObject("/V"): TextStringObject(fields[field])
})
elif writer_parent_annot.get('/T') == field:
writer_parent_annot.update({
NameObject("/V"): TextStringObject(fields[field])
})

def cloneReaderDocumentRoot(self, reader):
'''
Expand Down