PDF-Extract-Kit提取PDF数据

链接:
https://github.com/opendatalab/PDF-Extract-Kit

记录一下

首先是clone该项目,

然后新建一个虚拟环境

进入环境,进入项目
https://github.com/opendatalab/PDF-Extract-Kit?tab=readme-ov-file#installation-guide

如果报错没有PIL.Image.LINEAR,就

python 复制代码
pip uninstall detectron2
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2

然后下载模型:

python 复制代码
git lfs clone https://huggingface.co/wanderkid/PDF-Extract-Kit

这一步是得到一个文件夹,里面有models文件夹,把models替换到上面clone的项目的models,这样才能有权重。

最后放入pdf文件,run

python 复制代码
nohup python pdf_extract.py --pdf ../data/mrag.pdf --output ../output --vis > log.log 2>&1 &

最后提取为json保存
PDF-Extract-Kit输出格式

Bash 复制代码
{
    "layout_dets": [    # 页中的元素
        {
            "category_id": 0, # 类别编号, 0~9,13~15
            "poly": [
                136.0, # 坐标为图片坐标,需要转换回pdf坐标, 顺序是 左上-右上-右下-左下的x,y坐标
                781.0,
                340.0,
                781.0,
                340.0,
                806.0,
                136.0,
                806.0
            ],
            "score": 0.69,   # 置信度
            "latex": ''      # 公式识别的结果,只有13,14有内容,其他为空,另外15是ocr的结果,这个key会换成text
        },
        ...
    ],
    "page_info": {         # 页信息:提取bbox时的分辨率大小,如果有缩放可以基于该信息进行对齐
        "page_no": 0,      # 页数
        "height": 1684,    # 页高
        "width": 1200      # 页宽
    }
}


{0: 'title',              # 标题
 1: 'plain text',         # 文本
 2: 'abandon',            # 包括页眉页脚页码和页面注释
 3: 'figure',             # 图片
 4: 'figure_caption',     # 图片描述
 5: 'table',              # 表格
 6: 'table_caption',      # 表格描述
 7: 'table_footnote',     # 表格注释
 8: 'isolate_formula',    # 行间公式(这个是layout的行间公式,优先级低于14)
 9: 'formula_caption',    # 行间公式的标号

 13: 'inline_formula',    # 行内公式
 14: 'isolated_formula',  # 行间公式
 15: 'ocr_text'}              # ocr识别结果
相关推荐
Metaphor69215 小时前
使用 Python 给 PDF 设置背景色或背景图
数据库·python·pdf
2601_9618451519 小时前
新高考一卷真题2025|真题PDF全科整理
线性代数·矩阵·pdf·动态规划·概率论·高考
复园电子20 小时前
企业PDF批量盖章开发集成指南:API对接OA/LIMS系统,高并发落地实战
开发语言·python·pdf
2601_9618451521 小时前
2026四级作文预测题|英语四级写作押题+提纲PDF
java·c语言·数据库·c++·python·pdf·php
VBA说21 小时前
俄罗斯诚信码的批量识别,pdf文件也可
pdf
yuhulkjv3351 天前
Kimi如何导出pdf | AI导出鸭 独家深度测评
人工智能·ai·chatgpt·pdf·ai导出鸭
被放养的研究生1 天前
各软件中的 pt 有何不同?PDF 查看器、Draw.io 与 LaTeX 的单位陷阱
pdf·draw.io
2601_961845421 天前
2026四级作文预测26年|英语四级写作范文+模板PDF
java·数据库·spring·eclipse·pdf·tomcat·hibernate
DevOpenClub1 天前
用 OCR、PDF 转文本和摘要接口构建 RAG 文档入库 Agent
数据库·pdf·ocr
qq_422152572 天前
PDF 转 Word 哪个工具好用?2026 年主流方案对比与选型指南
pdf·word