首页 > 解决方案 > 从pdf中提取数据的最佳方法是什么

问题描述

我有数千个 pdf 文件需要从中提取数据。这是一个示例pdf。我想从示例 pdf 中提取此信息。

在此处输入图像描述

我对 nodejs、python 或任何其他有效方法持开放态度。我对python和nodejs知之甚少。我尝试在这段代码中使用 python

import PyPDF2

try:
   pdfFileObj = open('test.pdf', 'rb')
   pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
   pageNumber = pdfReader.numPages
   page = pdfReader.getPage(0)
   print(pageNumber)

   pagecontent = page.extractText()
   print(pagecontent)
except Exception as e:
   print(e)

但我被困在如何查找采购历史记录上。从 pdf 中提取采购历史的最佳方法是什么?

标签: pythonnode.jspdfpdf-scraping

解决方案


pdfplumber is the best option. [Reference]

Installation

pip install pdfplumber

Extract all the text

import pdfplumber
path = 'path_to_pdf.pdf'
with pdfplumber.open(path) as pdf:
    for  page  in pdf.pages:
        print(page.extract_text())

推荐阅读