问题
I wanted to decrypt a pdf file and write the first page into another file. Currently the code looks like this:
reader = PdfFileReader(infile)
if reader.isEncrypted:
reader.decrypt('')
writer = PdfFileWriter()
writer.addPage(reader.getPage(0))
pageObject = reader.getPage(0)
print 'First page of this file contains the following text:\n', pageObject.extractText()
with open('output.pdf', 'wb') as outfile:
writer.write(outfile)
The print function did output the content of the first page, so I knew the decryption worked. However, the writer.write function does not work. Error message is:
PyPDF2.utils.PdfReadError: Expected object ID (11 0) does not match actual (12 0).
What is the error and how can I fix it?
来源:https://stackoverflow.com/questions/52173955/python-pypdf2-writer-does-not-work-with-decryption