Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: append() fails when articles do not have /T #2080

Merged
merged 2 commits into from
Aug 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)