我有成千上万个只包含表格的PDF文件,结构如下所示:pdf file。虽然它们相当有结构,但我无法在不失去结构的情况下读取这些表格。我尝试了PyPDF2,但数据完全混乱。
我也试过Tabula,但它只能读取表头(而不能读取表格内容)。
有什么想法吗?
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])
我也试过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
有什么想法吗?
tabula-py
:https://pypi.org/project/tabula-py/ - ilja