Skip to content

Commit

Permalink
PI: Re-use content stream (#2101)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma authored Aug 20, 2023
1 parent 3033122 commit b532fa4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions pypdf/_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,12 +882,17 @@ def _content_stream_rename(

@staticmethod
def _push_pop_gs(
contents: Any, pdf: Union[None, PdfReaderProtocol, PdfWriterProtocol]
contents: Any,
pdf: Union[None, PdfReaderProtocol, PdfWriterProtocol],
use_original: bool = True,
) -> ContentStream:
# adds a graphics state "push" and "pop" to the beginning and end
# of a content stream. This isolates it from changes such as
# transformation matricies.
stream = ContentStream(contents, pdf)
if use_original:
stream = contents
else:
stream = ContentStream(contents, pdf)
stream.operations.insert(0, ([], "q"))
stream.operations.append(([], "Q"))
return stream
Expand Down Expand Up @@ -1120,7 +1125,7 @@ def _merge_page(
original_content = self.get_contents()
if original_content is not None:
new_content_array.append(
PageObject._push_pop_gs(original_content, self.pdf)
PageObject._push_pop_gs(original_content, self.pdf, use_original=True)
)

page2content = page2.get_contents()
Expand Down

0 comments on commit b532fa4

Please sign in to comment.