Skip to content

Commit

Permalink
BUG : fixes no attribute 'indirect_reference' error py-pdf#1723
Browse files Browse the repository at this point in the history
  • Loading branch information
pubpub-zz committed Mar 20, 2023
1 parent 1e4086e commit 439c1e0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,7 @@ def _get_qualified_field_name(self, parent: DictionaryObject) -> Optional[str]:
cast(DictionaryObject, parent["/Parent"])
)
if qualified_parent is not None:
return (
qualified_parent
+ "."
+ cast(str, parent["/T"])
)
return qualified_parent + "." + cast(str, parent["/T"])
return cast(str, parent["/T"])

def update_page_form_field_values(
Expand Down Expand Up @@ -2873,6 +2869,8 @@ def _insert_filtered_annotations(
if p is not None:
anc = ano.clone(self, ignore_fields=("/Dest",))
anc[NameObject("/Dest")] = ArrayObject([p] + d[1:])
if not hasattr(anc, "IndirectObject"):
anc = self._add_object(anc)
outlist.append(anc.indirect_reference)
else:
d = cast("DictionaryObject", ano["/A"])["/D"]
Expand Down
10 changes: 10 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,3 +1344,13 @@ def test_late_iss1654():
p.compress_content_streams()
b = BytesIO()
writer.write(b)


@pytest.mark.enable_socket()
def test_iss1723():
# test of an annotation(link) directly stored in the /Annots in the page
url = "https://github.com/py-pdf/pypdf/files/11015242/inputFile.pdf"
name = "iss1723.pdf"
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
out_pdf = PdfWriter()
out_pdf.append(in_pdf, (3, 5))

0 comments on commit 439c1e0

Please sign in to comment.