Skip to content

Commit

Permalink
BUG: Fix merging encrypted files (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 15, 2022
1 parent fe45d2e commit 9d53ee8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions PyPDF2/merger.py
Expand Up @@ -119,13 +119,13 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T
fileobj = StreamIO(filecontent)
my_file = True
elif isinstance(fileobj, PdfFileReader):
if hasattr(fileobj, '_decryption_key'):
decryption_key = fileobj._decryption_key
orig_tell = fileobj.stream.tell()
fileobj.stream.seek(0)
filecontent = StreamIO(fileobj.stream.read())
fileobj.stream.seek(orig_tell) # reset the stream to its original location
fileobj = filecontent
if hasattr(fileobj, '_decryption_key'):
decryption_key = fileobj._decryption_key
my_file = True

# Create a new PdfFileReader instance using the stream
Expand Down

0 comments on commit 9d53ee8

Please sign in to comment.