Python PyPDF2 writer does not work with decryption

坚强是说给别人听的谎言 提交于 2019-12-24 10:59:59

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!