gpt4 book ai didi

python - 我如何提取除 tabula 以外的 pdf 表格

转载 作者:行者123 更新时间:2023-12-04 07:16:52 24 4
gpt4 key购买 nike

我有一个工作脚本,我们必须在其中使用 tabula 包读取 pdf 表,但是由于 tabula 依赖于 Java 8,并且由于某些内部工具,我们必须使用 java 6 及以下版本,我们如何读取表。

from tabula import read_pdf
df_list = tabula.read_pdf(current_file, pages="all", lattice = True)

最佳答案

如何将 pdf 文档转换为 Excel 电子表格:
选项 1,使用 pdf_tables API:

  • 安装 pdf_tablespip install git+https://github.com/pdftables/python-pdftables-api.git
  • 获取账号 here

  • 安装完所有内容后,您可以运行以下代码:
    import pdftables_api

    c = pdftables_api.Client('my-api-key')
    c.xlsx('input.pdf', 'output')
    #replace c.xlsx with c.csv to convert to CSV
    #replace c.xlsx with c.xml to convert to XML
    #replace c.xlsx with c.html to convert to HTML
    #This is documentation code for your information
    不要忘记将 my-api-key 替换为您的 api key ,将 input.pdf 替换为您的 pdf 的路径,并将输出到您要将输出 excel 文档保存到的目录的路径。
    选项 2,使用 textract 读取 pdf,然后使用 xlwt 写入电子表格:
  • 使用 pip install textract 安装textract
  • 使用 pip install xlwt 安装 xlwt

  • 安装依赖项后,您可以运行以下代码:
    import textract
    import xlwt
    from xlwt import Workbook

    wb = Workbook()

    text = textract.process("path/to/file.extension") #You'll have to change this to your path to the file
    我不知道您的 pdf 是如何组织的,但您必须弄清楚如何从那里写入 excel 文档。 (您可以使用 sheet1.write(1, 0, 'Data'),其中 1 和 0 是您在电子表格上的坐标。
    我个人认为您应该使用 pdf_tables API 而不是手动进行转换。

    关于python - 我如何提取除 tabula 以外的 pdf 表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68714113/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com