【问题标题】:How can I extract text from a PDF file (without the header)?如何从 PDF 文件中提取文本(没有标题)?
【发布时间】:2021-06-09 03:49:13
【问题描述】:

我正在尝试使用 Python 从 PDF 文件中提取文本,我的主要目标是在主文件中提取不带标题的文本。

这是示例图像,标题指的是红色矩形: enter image description here

这里是 PDF 文件链接:https://mega.nz/file/d0YkhB5Y#j7eA0EBxg70Yu36PjGocNjouP_xQFoRRAN7VfyDeClo

目前将 PDF 文件中的文本提取为字符串的最佳和最简单的方法是什么? 我试过用pdfplumber,但是看了它的用户指南,还是不知道怎么用。

感谢您的帮助!!

【问题讨论】:

  • 你使用什么模块?你的代码在哪里?
  • this的可能重复

标签: python python-3.x pdf


【解决方案1】:

pdfplumber 的 repo 是 here。除了表格提取之外,它还是一个提取文本、字符、矩形和线条的好包。一个简单的例子是:

import pdfplumber

def extract_pdf(pdf_path):
    all_text = ''
    with pdfplumber.open(pdf_path) as pdf:
        for pdf_page in pdf.pages:
            single_page_text = pdf_page.extract_text()
            all_text = all_text + '\n' + single_page_text
    return all_text

pdf_path = 'test.pdf'
text = extract_pdf(pdf_path)
print(text)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 2018-06-14
    • 1970-01-01
    • 2011-04-30
    相关资源
    最近更新 更多