Skip to content

Commit

Permalink
BUG: append() fails when articles do not have /T (#2080)
Browse files Browse the repository at this point in the history
/T is optional

Closes #2078
  • Loading branch information
pubpub-zz authored Aug 12, 2023
1 parent f0781db commit f70dfad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f70dfad

Please sign in to comment.