【问题标题】:data missing while reading pdf file using tabula and python使用 tabula 和 python 读取 pdf 文件时数据丢失
【发布时间】:2020-04-01 02:53:38
【问题描述】:

我有一个包含多个文本和表格的 pdf,其中一行包含如下内容:

PDF content :
Id: 5647484848 Name Alex J

现在我正在使用 tabula-py 来解析内容,但结果丢失了一些东西(意味着你可以看到第一个字符或数字丢失了)。

实际上,我的原始 pdf 包含大量文本和表格。我也尝试了其他行,在那里我得到了正确的结果。

Wrong Result :
['', '', 'Id:', '', '647484848', 'Name', '', 'lex J', '', '', '']

Should be :
['', '', 'Id:', '', '5647484848', 'Name', '', 'Alex J', '', '', '']

示例:

# to get the exact row to find the name & index [7] is for Name
if len(row) == 11:
    if "Name" in row:
       print(row[7])
       return Student(studentname=row[7])

在看表的时候在tabula中,我已经设置了

df = tabula.read_pdf(pdf, output_format='json', pages='all',
                          password=secure_password, lattice=True)

该行是简单的文本类型,没有图像和所有。不知道为什么这个特定的行数据会失败。我已将类似的逻辑应用于我得到正确结果的其他行。请建议。

【问题讨论】:

  • 您可以将 pdf 中的违规行复制/粘贴到记事本文本文件中吗?如果不是,则该数据点的 pdf 可能会损坏。在 PDF 中,“您所看到的”不是“您可以提取的”,因为视觉字形和文本含义是分开存储的。它可能看起来不错,但“文本表示”可能是垃圾。如果是这样,您需要研究 pdf 上的 OCR 并从中获取缺失值。
  • 顺便说一句。 SO的坏问题 - 无法复制,无法解决。
  • @PatrickArtner 是的,我可以将其复制到文本编辑器中,这没有问题。我可以在那里查看原始内容。谢谢

标签: python pdf tabula tabula-py


【解决方案1】:

通过将 tabula-py 中的提取模式从 lattice=True 更改为 lattice=False 解决

df = tabula.read_pdf(pdf, output_format='json', pages='all',
                          password=secure_password, lattice=False)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2021-03-13
    • 1970-01-01
    • 1970-01-01
    • 2019-10-18
    相关资源
    最近更新 更多