Skip to content

Commit

Permalink
Fix Linked Form Value Issue py-pdf#398
Browse files Browse the repository at this point in the history
  • Loading branch information
malvidin authored Apr 5, 2018
1 parent 1775bdc commit 71f972f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,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 @@ -364,11 +365,18 @@ def updatePageFormFieldValues(self, page, fields):
# Iterate through pages, update field values
for j in range(0, len(page['/Annots'])):
writer_annot = page['/Annots'][j].getObject()
# retrieve parent field values, if present
if '/Parent' in writer_annot:
writer_parent_annot = page['/Annots'][j].getObject()['/Parent']
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

1 comment on commit 71f972f

@Kwilliams15
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to break on PDF's which do not have any parents as it attempts to reference writer_parent_annot prior to it's being set when line 372 is found to be false.

Please sign in to comment.