【问题标题】:Solving "EOF market not found error" PyPDF2解决“EOF 市场未找到错误”PyPDF2
【发布时间】:2019-10-02 03:15:19
【问题描述】:

我正在使用 PyPDF2 和 tika 从 .pdf 和 .htm 文件中提取文本。 我遇到以下错误: “PyPDF2.utils.PdfReadError:找不到 EOF 标记”

我已经看到多篇关于这个问题的帖子,但没有一个包含解决方案。

这是我正在使用的代码:

from xlwt import Workbook

import PyPDF2, os

from tika import parser


wb = Workbook()

sheet1 = wb.add_sheet('Sheet 1')
sheet1.write(0, 0, 'file name')
sheet1.write(0, 1, 'file content')

pdfFiles = []
folderPath = 'C:/Users/Turing/Desktop/workingFiles' #! define the path for the folder including input files

for filename in os.listdir(folderPath):
    if filename.endswith('.htm') or filename.endswith('.pdf'):
        pdfFiles.append(filename)

pdfFiles.sort(key=str.lower)

row = 0

for filename in pdfFiles:
    row = row + 1
    #print(filename)
    sheet1.write(row, 0, filename)  # write the name of the file to column number 0 of output
    filename = folderPath+'\\'+filename
    pdfFileObj = open(filename, 'rb')
    pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
    raw = parser.from_file(filename)
    #print(raw['content'])
    sheet1.write(row, 1, raw['content']) # write the content of the input doc to column number 1 of the output

wb.save('MRS.xls')

我已上传one of the problematic files供您参考。

【问题讨论】:

    标签: python eof pypdf2 pdf-reader


    【解决方案1】:

    您正在使用 PyPDF2.PdfFileReader 读取 HTML 文件,该文件需要 PDF 文件。 可能最容易分成

    pdfFiles = []
    htmFiles = []
    for filename in os.listdir(folderPath):
        if filename.endswith('.pdf'):
            pdfFiles.append(filename)
        if filename.endswith('.htm'):
            htmFiles.append(filename)
    

    并分别解析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      • 2016-05-16
      • 2017-01-22
      相关资源
      最近更新 更多