Skip to content

Commit ee0ace6

Browse files
committed
Merge pull request py-pdf#210 from underdogio/dev/copy.encryption.sqwished
Added decryption key copying for PdfFileMerger
2 parents 7ea13fc + 541963c commit ee0ace6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

PyPDF2/merger.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T
109109
# it is a PdfFileReader, copy that reader's stream into a
110110
# BytesIO (or StreamIO) stream.
111111
# If fileobj is none of the above types, it is not modified
112+
decryption_key = None
112113
if isString(fileobj):
113114
fileobj = file(fileobj, 'rb')
114115
my_file = True
@@ -123,11 +124,15 @@ def merge(self, position, fileobj, bookmark=None, pages=None, import_bookmarks=T
123124
filecontent = StreamIO(fileobj.stream.read())
124125
fileobj.stream.seek(orig_tell) # reset the stream to its original location
125126
fileobj = filecontent
127+
if hasattr(fileobj, '_decryption_key'):
128+
decryption_key = fileobj._decryption_key
126129
my_file = True
127130

128131
# Create a new PdfFileReader instance using the stream
129132
# (either file or BytesIO or StringIO) created above
130133
pdfr = PdfFileReader(fileobj, strict=self.strict)
134+
if decryption_key is not None:
135+
pdfr._decryption_key = decryption_key
131136

132137
# Find the range of pages to merge.
133138
if pages == None:

0 commit comments

Comments
 (0)