2
我正在檢查文件系統中的損壞的PDF。在我正在運行的測試中,有近200k PDF。看起來好像更小的損壞的文件警報正確,但我碰到一個大的15 MB文件損壞,代碼只能無限期地掛起。我試過將Strict設置爲False而沒有運氣。這似乎是最初的問題。而不是做線程和設置超時(我曾嘗試在過去很少成功),我希望有一個替代方案。PyPDF2 - 無法過去。一個大的損壞的文件
import PyPDF2, os
from time import gmtime,strftime
path = raw_input("Enter folder path of PDF files:")
t = open(r'c:\pdf_check\log.txt','w')
count = 1
for dirpath,dnames,fnames in os.walk(path):
for file in fnames:
print count
count = count + 1
if file.endswith(".pdf"):
file = os.path.join(dirpath, file)
try:
PyPDF2.PdfFileReader(file,'rb',warndest="c:\test\warning.txt")
except PyPDF2.utils.PdfReadError:
curdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
t.write(str(curdate) + " " + "-" + " " + file + " " + "-" + " " + "fail" + "\n")
else:
pass
#curdate = strftime("%Y-%m-%d %H:%M:%S", gmtime())
#t.write(str(curdate) + " " + "-" + " " + file + " " + "-" + " " + "pass" + "\n")
t.close()