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: Fix merge_page sometimes generating unknown operator 'QQ' #2588

Merged
merged 6 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,7 @@ def isolate_graphics_state(self) -> None:
self._operations.insert(0, ([], "q"))
self._operations.append(([], "Q"))
elif self._data:
self._data = b"q\n" + b_(self._data) + b"Q\n"
self._data = b"q\n" + b_(self._data) + b"\nQ"
rfotino marked this conversation as resolved.
Show resolved Hide resolved

# This overrides the parent method:
def write_to_stream(
Expand Down
11 changes: 11 additions & 0 deletions tests/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,17 @@ def test_pdf_pages_missing_type():
writer.pages[0]


@pytest.mark.samples()
def test_merge_with_stream_ending_in_Q():
rfotino marked this conversation as resolved.
Show resolved Hide resolved
"""Test for issue #2587"""
reader = PdfReader(SAMPLE_ROOT / "027-blank-push-pop/blank.pdf")
page_one = reader.pages[0]
assert b"q Q" == page_one.get_contents()._data
page_two = reader.pages[0]
page_one.merge_page(page_two)
assert b"QQ" not in page_one.get_contents()._data
rfotino marked this conversation as resolved.
Show resolved Hide resolved


@pytest.mark.samples()
def test_compression():
"""Test for issue #1897"""
Expand Down
Loading