Skip to content

Commit

Permalink
Properly fixing test_remove_images[side-by-side-subfig.pdf]
Browse files Browse the repository at this point in the history
  • Loading branch information
Cimon Lucas (LCM) committed Aug 20, 2023
1 parent 4a0be88 commit e4d12ab
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions pypdf/_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,6 +2194,7 @@ def clean(content: ContentStream) -> None:
i += 1
else:
i += 1
content.get_data() # this ensures ._data is rebuilt

try:
d = cast(dict, cast(DictionaryObject, page["/Resources"])["/XObject"])
Expand Down
2 changes: 1 addition & 1 deletion pypdf/generic/_data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def write_to_stream(
deprecate_no_replacement(
"the encryption_key parameter of write_to_stream", "5.0.0"
)
self[NameObject(SA.LENGTH)] = NumberObject(len(self.get_data()))
self[NameObject(SA.LENGTH)] = NumberObject(len(self._data))
DictionaryObject.write_to_stream(self, stream)
del self[SA.LENGTH]
stream.write(b"\nstream\n")
Expand Down
2 changes: 2 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ def test_remove_images(pdf_file_path, input_path):
page = reader.pages[0]
writer.insert_page(page, 0)
writer.remove_images()
page_contents_stream = writer.pages[0]["/Contents"]._data
assert len(page_contents_stream.strip())

# finally, write "output" to pypdf-output.pdf
with open(pdf_file_path, "wb") as output_stream:
Expand Down

0 comments on commit e4d12ab

Please sign in to comment.