【问题标题】:Extracting text from pdf containing multiple columns with pdfplumber (Python)使用pdfplumber(Python)从包含多列的pdf中提取文本
【发布时间】:2020-10-08 09:59:39
【问题描述】:

我正在从 pdf(使用 python)中提取文本以分析它们,因此我经常处理科学论文。我正在使用 pdfplumber,它运行良好,唯一的问题是此类 pdf 通常包含 columns,我还没有找到让我的算法识别这一点的方法。 p>

我的代码是:

text = ""
with pdfplumber.open(r'example.pdf') as pdf:
    pages = pdf.pages
    for i, pg in enumerate(pages):
        text = text + " " + pages[i].extract_text(x_tolerance = 1)
text = text.replace('\n',' ')
text = text.replace('\r',' ')
text = text.replace('\no',' ')
text = text.replace('\nD',' ')
text = text.lower()
text = re.sub(r'[^a-zA-Z0-9\s]', ' ', text)

你知道一个可能对我有帮助的函数吗?谢谢!

【问题讨论】:

  • 问题解决了吗?你能更新一下状态吗

标签: python multiple-columns text-extraction


【解决方案1】:

假设列由" " 分隔,那么您可以使用draw_rects() 函数从列中制作文本。

该过程要求您首先使用检测charsspaces

im.reset().draw_rects(p0.chars)

然后使用

text = p0.extract_text()

将为您提供列的文本格式。这个例子说明了它是如何做到的 - Extract the column text from the PDF

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多