【问题标题】:Extract fixed size and position table from pdf files in Python从Python中的pdf文件中提取固定大小和位置表
【发布时间】:2021-07-08 02:43:38
【问题描述】:

假设我有许多与here 类似的 pdf 文件:

我想提取下表并保存为 excel 文件:

我可以使用 excalibur 包手动提取表格并保存 excel 文件。

使用 pip3 安装 Excalibur 后,我使用以下方法初始化元数据数据库:

$ excalibur 初始化数据库

然后使用以下命令启动网络服务器:

$ excalibur 网络服务器

然后转到 http://localhost:5000 并开始从 PDF 中提取表格数据。

我想知道是否可以使用 python 脚本为多个 pdf 文件自动执行此操作,这些文件包含 excalibur-pycamelotpdfminer 等包,因为表格的大小和位置对于同一个城市的报告是固定的.

您可以从this link下载其他报告文件。

非常感谢。

【问题讨论】:

    标签: python-3.x text-extraction pdfminer python-camelot excalibur-py


    【解决方案1】:

    使用 Camelot,您可以像这样构建管道:

    import camelot
    
    files_list=['FIRST_PATH','SECOND_PATH',...]
    regions=['REGION_COORDINATES_1', 'REGION_COORDINATES_2',...]
    
    for filepath in files_list:
        tables=camelot.read_pdf(filepath, pages='1-end', table_regions=regions)
        tables.export('tables.xls', f='excel')
    

    table_regions 参数应在您知道表格在页面内的大致位置时使用;如果你知道桌子的确切位置,你应该使用table_areas

    您可以在Camelot documentation 中阅读有关这些参数和其他主题的更多信息。

    【讨论】:

    • 谢谢,请问如何从pdf文件中找到表格区域?
    • 您可以使用可视化调试 (camelot-py.readthedocs.io/en/master/user/…)。否则,如果您还没有提取表格,您可以通过table._bbox获取坐标。
    猜你喜欢
    • 1970-01-01
    • 2015-03-19
    • 2011-09-08
    • 2021-05-30
    • 2022-10-31
    • 1970-01-01
    • 2023-02-20
    • 2021-11-14
    • 2012-04-14
    相关资源
    最近更新 更多