【发布时间】:2025-12-08 22:00:02
【问题描述】:
我正在尝试将文档的特定部分作为表格读取。它采用表格结构,但在单元格、行或列之间没有分隔线。
我成功地使用了带有area 和column 参数的read_pdf() 方法。我可以准确地指定表格的开始和结束位置以及列的划分位置。
但是我的 pdf 在每个页面上都有多个不同大小的表格,没有明确的标记来识别它们,我必须使用这些参数。
我在 Github 存储库问题 here 中发现了 read_pdf_with_template() 方法,并在 documentation、pull request 和 example notebook 中了解了更多信息。
但没有提到如何构建teamplate.json 以及我可以使用哪些参数或它们的含义。
我尝试将area 坐标插入x1, y1, x2, y2,在方法参数中传递列列表,并将height、width 参数与表的大小一起传递。
但它正在拾取 pdf 的顶部中心部分,这不等于我在反向计算所有内容时插入的任何坐标。
这里是代码sn-ps
import tabula
tables = tabula.read_pdf_with_template(input_path = "test.pdf", template_path = "template.json", columns=[195, 310, 380])
print(tables[0])
[
{
"page": 1,
"extraction_method": "stream",
"x1": 225,
"x2": 35,
"y1": 375,
"y2": 565,
"width": 525,
"height": 400
}
]
【问题讨论】: