我有数千个 PDF 文件,仅由表格组成,结构如下:
然而,尽管结构相当合理,但我无法在不丢失结构的情况下阅读表格。
我尝试了 PyPDF2,但数据完全混乱。
import PyPDF2
pdfFileObj = open(pdf_file.pdf, 'rb')
pdfReader = PyPDF2.PdfFileReader(pdfFileObj)
pageObj = pdfReader.getPage(0)
print(pageObj.extractText())
print(pageObj.extractText().split('\n')[0])
print(pageObj.extractText().split('/')[0])
Run Code Online (Sandbox Code Playgroud)
我也尝试过 Tabula,但它只读取标题(而不是表格的内容)
from tabula import read_pdf
pdfFile1 = read_pdf(pdf_file.pdf, output_format = 'json') #Option 1: reads all the headers
pdfFile2 = read_pdf(pdf_file.pdf, multiple_tables = True) #Option 2: reads only the first header and few lines of content
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我想从pdf 文档中提取一个表
我尝试了pdf的路线 - > html - >提取表.转换为html时我上面提到的pdf产生垃圾,可能是因为字体,文件不是英文的.
因为这样的解决方案需要从URL上面提到的,这将有表,但不总是在相同的位置未来的PDF工作用x提取PDF和y坐标是不是一种选择.
请帮忙,
提前致谢.