diff --git a/pypdf/_writer.py b/pypdf/_writer.py index 29b3e4a7f..83ddee5d3 100644 --- a/pypdf/_writer.py +++ b/pypdf/_writer.py @@ -3085,7 +3085,11 @@ def add_filtered_articles( for p in pages.values(): pp = p.original_page for a in pp.get("/B", ()): - thr = a.get_object()["/T"] + thr = a.get_object().get("/T") + if thr is None: + continue + else: + thr = thr.get_object() if thr.indirect_reference.idnum not in self._id_translated[ id(reader) ] and fltr.search(thr["/I"]["/Title"]): diff --git a/tests/test_writer.py b/tests/test_writer.py index 58fff1417..335c34920 100644 --- a/tests/test_writer.py +++ b/tests/test_writer.py @@ -1589,3 +1589,13 @@ def test_missing_info(): writer = PdfWriter(clone_from=reader) assert len(writer.pages) == len(reader.pages) + + +@pytest.mark.enable_socket() +def test_no_t_in_articles(): + """Cf #2078""" + url = "https://github.com/py-pdf/pypdf/files/12311735/bad.pdf" + name = "iss2078.pdf" + reader = PdfReader(BytesIO(get_data_from_url(url, name=name))) + writer = PdfWriter() + writer.append(reader)