Skip to content

Commit 9d53ee8

Browse files
authored
BUG: Fix merging encrypted files (#757)
1 parent fe45d2e commit 9d53ee8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

PyPDF2/merger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T
119119
fileobj = StreamIO(filecontent)
120120
my_file = True
121121
elif isinstance(fileobj, PdfFileReader):
122+
if hasattr(fileobj, '_decryption_key'):
123+
decryption_key = fileobj._decryption_key
122124
orig_tell = fileobj.stream.tell()
123125
fileobj.stream.seek(0)
124126
filecontent = StreamIO(fileobj.stream.read())
125127
fileobj.stream.seek(orig_tell) # reset the stream to its original location
126128
fileobj = filecontent
127-
if hasattr(fileobj, '_decryption_key'):
128-
decryption_key = fileobj._decryption_key
129129
my_file = True
130130

131131
# Create a new PdfFileReader instance using the stream

0 commit comments

Comments
 (0)