我正在尝试使用Python中的camelot从PDF文件中提取表格及其名称。虽然我知道如何使用camelot提取表格(这很简单明了),但是我在寻求如何提取表格名称的帮助时遇到了困难。我的意图是提取此信息并展示一个表格的可视化,以便用户从列表中选择相关的表格。
我已经尝试从PDF文件中提取表格和文本。两者都成功了,但是我没有将表格名称与表格连接起来的方法。
预期结果是一个表格及其在pdf文件中所列的名称。例如: PDF第x页上的表格名称为:Table 1. Blah Blah blah '''表格'''
我已经尝试从PDF文件中提取表格和文本。两者都成功了,但是我没有将表格名称与表格连接起来的方法。
def tables_from_pdfs(filespath):
pdffiles = glob.glob(os.path.join(filespath, "*.pdf"))
print(pdffiles)
dictionary = {}
keys = []
for file in pdffiles:
print(file)
n = PyPDF2.PdfFileReader(open(file, 'rb')).getNumPages()
print(n)
tables_dict = {}
for i in range(n):
tables = camelot.read_pdf(file, pages = str(i))
tables_dict[i] = tables
head, tail = os.path.split(file)
tail = tail.replace(".pdf", "")
keys.append(tail)
dictionary[tail] = tables_dict
return dictionary, keys
预期结果是一个表格及其在pdf文件中所列的名称。例如: PDF第x页上的表格名称为:Table 1. Blah Blah blah '''表格'''