From 7a807d226aea90e60f22281a8e1d7317ba87d1d7 Mon Sep 17 00:00:00 2001 From: pubpub-zz <4083478+pubpub-zz@users.noreply.github.com> Date: Sat, 11 Feb 2023 14:37:10 +0100 Subject: [PATCH] ROB: Fix 2 cases of "object has no attribute 'indirect_reference'" (#1616) Fixes #1614 --- pypdf/_writer.py | 8 +++----- tests/test_writer.py | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pypdf/_writer.py b/pypdf/_writer.py index f6cd581af..9b46e6df0 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -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: @@ -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): diff --git a/tests/test_writer.py b/tests/test_writer.py index 41b35296c..3f09c4f4e 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -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)