Skip to content

Commit

Permalink
ROB: Fix 2 cases of "object has no attribute 'indirect_reference'" (#…
Browse files Browse the repository at this point in the history
…1616)

Fixes #1614
  • Loading branch information
pubpub-zz authored Feb 11, 2023
1 parent c70dcd0 commit 7a807d2
Show file tree
Hide file tree
Showing 2 changed files with 17 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 @@ -2605,13 +2605,11 @@ def merge(

if "/AcroForm" in cast(DictionaryObject, reader.trailer["/Root"]):
if "/AcroForm" not in self._root_object:
self._root_object[NameObject("/AcroForm")] = (
self._root_object[NameObject("/AcroForm")] = self._add_object(
cast(
DictionaryObject,
cast(DictionaryObject, reader.trailer["/Root"])["/AcroForm"],
)
.clone(self, False, ("/Fields",))
.indirect_reference
).clone(self, False, ("/Fields",))
)
arr = ArrayObject()
else:
Expand Down Expand Up @@ -2765,7 +2763,7 @@ def _insert_filtered_annotations(
or "/Dest" in ano
):
if "/Dest" not in ano:
outlist.append(ano.clone(self).indirect_reference)
outlist.append(self._add_object(ano.clone(self)))
else:
d = ano["/Dest"]
if isinstance(d, str):
Expand Down
14 changes: 14 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,3 +1175,17 @@ def test_iss1601():
ContentStream(in_pdf.pages[0].get_contents(), in_pdf).get_data()
in page_1.get_contents().get_data()
)


def test_iss1614():
# test of an annotation(link) directly stored in the /Annots in the page
url = "https://github.com/py-pdf/pypdf/files/10669995/broke.pdf"
name = "iss1614.pdf"
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
out_pdf = PdfWriter()
out_pdf.append(in_pdf)
# test for 2nd error case reported in #1614
url = "https://github.com/py-pdf/pypdf/files/10696390/broken.pdf"
name = "iss1614.2.pdf"
in_pdf = PdfReader(BytesIO(get_pdf_from_url(url, name=name)))
out_pdf.append(in_pdf)

0 comments on commit 7a807d2

Please sign in to comment.