Skip to content

Commit

Permalink
BUG: Stream operations can be List or Dict (#665)
Browse files Browse the repository at this point in the history
Appeared when merging PDFs that have content-stream-inline images

This patch was provided by Georg Graf :
#196 (comment)
Thank you!

Closes #196
  • Loading branch information
MartinThoma authored Apr 7, 2022
1 parent 1e46d84 commit 3eadff0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2255,10 +2255,18 @@ def _contentStreamRename(stream, rename, pdf):
return stream
stream = ContentStream(stream, pdf)
for operands, _operator in stream.operations:
for i in range(len(operands)):
op = operands[i]
if isinstance(op, NameObject):
operands[i] = rename.get(op,op)
if isinstance(operands, list):
for i in range(len(operands)):
op = operands[i]
if isinstance(op, NameObject):
operands[i] = rename.get(op,op)
elif isinstance(operands, dict):
for i in operands:
op = operands[i]
if isinstance(op, NameObject):
operands[i] = rename.get(op,op)
else:
raise KeyError ("type of operands is %s" % type (operands))
return stream
_contentStreamRename = staticmethod(_contentStreamRename)

Expand Down

0 comments on commit 3eadff0

Please sign in to comment.