From 3eadff034c10cbb7b69b921e13c9e42b0ebb9f14 Mon Sep 17 00:00:00 2001 From: Martin Thoma Date: Thu, 7 Apr 2022 18:14:40 +0200 Subject: [PATCH] BUG: Stream operations can be List or Dict (#665) Appeared when merging PDFs that have content-stream-inline images This patch was provided by Georg Graf : https://github.com/mstamy2/PyPDF2/issues/196#issuecomment-172829990 Thank you! Closes #196 --- PyPDF2/pdf.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/PyPDF2/pdf.py b/PyPDF2/pdf.py index fb0eccdda..f932d7f15 100644 --- a/PyPDF2/pdf.py +++ b/PyPDF2/pdf.py @@ -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)