【问题标题】:PyPDF2 - Unable to Get Past. A Large Corrupted FilePyPDF2 - 无法过去。一个大的损坏的文件
【发布时间】:2017-10-12 21:14:00
【问题描述】:

我正在检查文件系统中损坏的 PDF。在我正在运行的测试中,有将近 200k PDF。似乎较小的损坏文件正确警报,但我遇到了一个已损坏的 15 MB 大文件,代码只是无限期挂起。我尝试将 Strict 设置为 False,但没有运气。似乎问题在于最初的开放。而不是做线程和设置超时(我过去尝试过但收效甚微),我希望有一个替代方案。

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()

【问题讨论】:

    标签: python pdf pypdf2


    【解决方案1】:

    PyPDF2 似乎存在问题。我无法让它工作,但是,我使用了 pdfrw,它并没有在这一点上停止,而是毫无问题地浏览了所有几十万个文档。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-26
      • 2015-08-07
      • 2012-07-21
      • 2011-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多