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识别结果
相关推荐
redfred8 小时前
Stirling-PDF 使用教程:开源 PDF 工具箱 50+ 工具 PDF转Word/合并/压缩/OCR 桌面版 Docker 部署详解
pdf·开源·word
2501_9307077811 小时前
如何使用C#代码向 PDF 文档添加多种类型的注释
pdf
SamChan9016 小时前
Python+PyMuPDF提取PDF表格并翻译:表格结构检测与双语重建实战
windows·python·ai·pdf·wpf
E_ICEBLUE16 小时前
Python 实现 Markdown 转 Word、PDF:从转换到页面设置
python·pdf·word·markdown·格式转换
zhonyu鱼16 小时前
Drawpile:多人实时协作绘画,一起在同一块画布上画画
笔记·pdf·开源·开源软件
SamChan9017 小时前
Python+OpenCV检测PDF翻译后排版偏移:像素级格式一致性验证
python·opencv·ai·pdf·wpf
todoitbo17 小时前
PDF 合并、转换也能自己部署:极空间运行 Stirling PDF,文件交给自己的服务器处理
网络安全·pdf·文件·nas·极空间
专家大圣17 小时前
给自己搭一个 PDF 工具站:Stirling-PDF 部署、格式转换与远程访问实战
网络·pdf·内网穿透
XLYcmy1 天前
PDF论文处理器 - 完整使用指南
pdf·llm·json·agent·token·csv·dify
小新科研测评2 天前
2026 年论文阅读工具横评:Zotero、EndNote、Mendeley、Scholaread 哪个效率更高?
论文阅读·人工智能·ai·pdf·自动翻译