[英]How to read this pdf form using PyPDF2 in python
https://www.fda.gov/downloads/AboutFDA/ReportsManualsForms/Forms/UCM074728.pdf
我正在嘗試使用PyPDF2或Pdfminer讀取此pdf文件,但它表示該文件尚未在Pypdf2和pdfminer中解密,它表示可以解壓縮該pdf文件。 有人讓我知道如何在python3 Windows環境中執行此操作。 我無法使用poppler,因為無法在此Windows中安裝poppler。
這是受限制的PDF文件。 在大多數情況下,您可以使用帶有空字符串的PyPDF2解密不會提示您輸入密碼的文件:
from PyPDF2 import PdfFileReader
reader = PdfFileReader('sample.pdf')
reader.decrypt('')
不幸的是,您的文件或任何其他具有128-bit AES
加密級別的文件decrypt()
並非PyPDF2 delete decrypt()
方法不支持decrypt()
會返回NotImplementedError
。
作為一種簡單的解決方法,您可以將此文件另存為Adobe Reader或類似文件中的新文件,並且新文件應適用於您的代碼。
另外,您可以使用qpdf
以編程方式完成此qpdf
如本GitHub問題中所述 :
import os, shutil, tempdir
from subprocess import check_call
try:
tempdir = tempfile.mkdtemp(dir=os.path.dirname(filename))
temp_out = os.path.join(tempdir, 'qpdf_out.pdf')
check_call(['qpdf', "--password=", '--decrypt', filename, temp_out])
shutil.move(temp_out, filename)
print 'File Decrypted'
finally:
shutil.rmtree(tempdir)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.