![](/img/trans.png)
[英]How i can extract only text without tables inside a pdf file using PDFplumber?
[英]How can I extract text from a PDF file (without the header)?
我正在嘗試使用 Python 從 PDF 文件中提取文本,我的主要目標是在沒有 header 的主文件中提取文本。
這是示例圖像,header 指的是紅色矩形:在此處輸入圖像描述
這是 PDF 文件鏈接: https://mega.nz/file/d0YkhB5Y#j7eA0EBxg70Yu36PjGocNjouP_xQFoRRAN7VfyDeClo
目前從 PDF 文件中提取文本到字符串中最好和最簡單的方法是什么? 我曾嘗試使用 pdfplumber,但在閱讀了它的用戶指南后,我仍然不知道如何使用它。
謝謝你的幫助!!
pdfplumber的 repo 在這里。 除了表格提取之外,還可以提取文本、字符、矩形和線條,是一款很棒的 package。 一個簡單的例子是:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.