Python PdfReadError:文件尚未解密
目前我正在使用PyPDF 2,我还尝试将PyPDF 4作为依赖项 我遇到了一些加密文件,并按照您通常的方式(在以下代码中)处理它们: 这会产生以下错误:Python PdfReadError:文件尚未解密,python,pdf,image-processing,ocr,pypdf,Python,Pdf,Image Processing,Ocr,Pypdf,目前我正在使用PyPDF 2,我还尝试将PyPDF 4作为依赖项 我遇到了一些加密文件,并按照您通常的方式(在以下代码中)处理它们: 这会产生以下错误: PdfReadError: File has not been decrypted 我可以将pdf文件调用为pdfFileObj变量。但当它点击print PDF.getNumPages()时,仍然会引发错误,“PyPDF2.utils.PdfReadError:文件尚未解密” 我如何消除这个错误?我可以通过双击打开PDF文件(默认情况下,A
PdfReadError: File has not been decrypted
我可以将pdf文件调用为pdfFileObj变量。但当它点击print PDF.getNumPages()时,仍然会引发错误,“PyPDF2.utils.PdfReadError:文件尚未解密”
我如何消除这个错误?我可以通过双击打开PDF文件(默认情况下,Adobe Reader会打开该文件)。我也看到过同样的问题。我得出的结论是PyPdf2不可信!如果可以的话,我建议你尝试另一种选择。您可能喜欢PIKEDF,它是在QPDF(一个著名的C++库)之上编写的:< P>可以使用“QPDF”库连同子进程对给定的PDF文件进行解密。
sudo apt-get install -y qpdf
此代码段解密pdf文件(文件路径)并将其保存到新的文件路径中
new_file_path = file_path.replace('.pdf','_decrypt.pdf').replace('.PDF','_decrypt.pdf')
cmd = "qpdf --decrypt " + file_path + " " + new_file_path
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, preexec_fn=os.setsid)
stdout, stderr = proc.communicate()
new_file_path = file_path.replace('.pdf','_decrypt.pdf').replace('.PDF','_decrypt.pdf')
cmd = "qpdf --decrypt " + file_path + " " + new_file_path
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True, preexec_fn=os.setsid)
stdout, stderr = proc.communicate()