Skip to content

Commit

Permalink
test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz committed Feb 28, 2024
1 parent c8ba914 commit f23f01e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,10 @@ def reattach_fields(
indirect = isinstance(ano, IndirectObject)
ano = cast(DictionaryObject, ano.get_object())
if ano.get("/Subtype", "") == "/Widget" and "/FT" in ano:
if ano.indirect_reference in fields:
if (
"indirect_reference" in ano.__dict__
and ano.indirect_reference in fields
):
continue
if not indirect:
annots[idx] = self._add_object(ano)
Expand Down
12 changes: 12 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,3 +1999,15 @@ def test_reattach_fields():
assert len(writer.reattach_fields()) == 7
writer.reattach_fields()
assert len(writer._root_object["/AcroForm"]["/Fields"]) == 15

writer = PdfWriter()
for p in reader.pages:
writer.add_page(p)
ano = writer.pages[0]["/Annots"][0].get_object()
del ano.indirect_reference
writer.pages[0]["/Annots"][0] = ano
assert isinstance(writer.pages[0]["/Annots"][0], DictionaryObject)
assert len(writer.reattach_fields(writer.pages[0])) == 6
assert isinstance(writer.pages[0]["/Annots"][0], IndirectObject)
del writer.pages[1]["/Annots"]
assert len(writer.reattach_fields(writer.pages[1])) == 0

0 comments on commit f23f01e

Please sign in to comment.