OpenSource-Hub

opendataloader-pdf

opendataloader-project/opendataloader-pdf

用于 AI 数据提取和无障碍化的 PDF 解析器。

项目简介

开源 PDF 解析器,提取结构化数据(Markdown、JSON、HTML),包含边界框、阅读顺序和表格支持。自动将未标记 PDF 转换为标记 PDF 以实现无障碍化,可选企业级 PDF/UA 导出。在提取准确性基准测试中排名第一。

README 预览

\n\n# OpenDataLoader PDF\n\n**PDF Parser for AI-ready data. Automate PDF accessibility. Open-source.**\n\n[](https://github.com/opendataloader-project/opendataloader-pdf/blob/main/LICENSE)\n[](https://pypi.org/project/opendataloader-pdf/)\n[](https://www.npmjs.com/package/@opendataloader/pdf)\n[](https://search.maven.org/artifact/org.opendataloader/opendataloader-pdf-core)\n[](https://github.com/opendataloader-project/opendataloader-pdf#java)\n\n\n\n🔍 **PDF parser for AI data extraction** — Extract Markdown, JSON (with bounding boxes), and HTML from any PDF. #1 in benchmarks (0.907 overall). Deterministic local mode + AI hybrid mode for complex pages.\n\n- **How accurate is it?** — #1 in benchmarks: 0.907 overall, 0.928 table accuracy across 200 real-world PDFs including multi-column and scientific papers. Deterministic local mode + AI hybrid mode for complex pages ([benchmarks](#extraction-benchmarks))\n- **Scanned PDFs and OCR?** — Yes. Built-in OCR (80+ languages) in hybrid mode. Works with poor-quality scans at 300 DPI+ ([hybrid mode](#hybrid-mode-1-accuracy-for-complex-pdfs))\n- **Tables, formulas, images, charts?** — Yes. Complex/borderless tables, LaTeX formulas, and AI-generated picture/chart descriptions all via hybrid mode ([hybrid mode](#hybrid-mode-1-accuracy-for-complex-pdfs))\n- **How do I use this for RAG?** — `pip install opendataloader-pdf`, convert in 3 lines. Outputs structured Markdown for chunking, JSON with bounding boxes for source citations, and HTML. LangChain integration available. Python, Node.js, Java SDKs ([quick start](#get-started-in-30-seconds) | [LangChain](#langchain-integration))\n\n♿ **PDF accessibility automation** — Auto-tag untagged PDFs into screen-reader-ready Tagged PDFs at scale. First open-source tool to generate Tagged PDFs end-to-end.\n\n- **What's the problem?** — Accessibility regulations are now enforced worldwide. Manual PDF remediation costs $50–200 per document and doesn't scale ([regulations](#pdf-accessibility--

常见问题 (5)

故障排除
为什么在不使用--quiet标志时,opendataloader-pdf会打印两次输出?

一个bug导致在未设置--quiet选项时,stdout输出被重复。该修复在流式模式下用空字符串解析promise,以防止CLI双重写入。更新到最新版本的opendataloader-pdf,或手动应用PR #399的更改:在src/index.ts中,在executeJar函数中,将resolve调用改为resolve(streamOutput ? '' : stdout)

来源 Issue #398
故障排除
为什么在 OpenDataLoaderPDF.processFile 之后删除 PDF 会失败,出现“该文件无法删除,因为它正被另一个进程使用”的错误?

在 OpenDataLoader 2.2.1 中,PDF PDDocument 及相关资源在处理后未正确关闭,导致文件锁定持续存在。要修复此问题,请添加一个资源清理方法,并将现有的 processFile 逻辑包装在 try-finally 块中。在 DocumentProcessor.java 中实现以下代码:

// 添加此方法
private static void closePdfResources() {
    try {
        StaticLayoutContainers.closeContrastRatioConsumer();
    } catch (Exception e) {
        LOGGER.log(Level.WARNING, "Unable to close contrast ratio consumer: " + e.getMessage());
    }
    PDDocument document = StaticResources.getDocument();
    if (document != null) {
        try {
            document.close();
        } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Unable to close PDF document: " + e.getMessage());
        }
    }
}

// 将 processFile 主体包装在 try-finally 块中
public static void processFile(String inputPdfName, Config config) throws IOException {
    try {
        // ... 原始代码 ...
    } finally {
        closePdfResources();
    }
}

应用此修复后,处理完文件即可立即删除。

来源 Issue #408
故障排除
当原始PDF文件名包含空格时,为什么生成的markdown中图片无法显示?

markdown转换器生成的图片链接中包含未转义的空格,导致渲染器在第一个空格处截断路径(例如![image](my paper_images/image.png))。解决方法是将图片路径包裹在尖括号中:![image](<my paper_images/image.png>)。这符合CommonMark §6.4规范,可确保图片在VS Code、GitHub及大多数渲染器中正确显示。该修复已包含在提交4b87a30(PR #468)中。

来源 Issue #405
故障排除
如何修复使用opendataloader_pdf转换PDF时出现的"subprocess.CalledProcessError: returned non-zero exit status 1"错误?

该错误是由处理特定PDF(例如QuarkXPress生成的文件)时的图像提取逻辑缺陷引起的。该问题已在较新版本中修复。请使用pip升级opendataloader_pdf至最新版本(v2.0.3或更高版本):pip install --upgrade opendataloader_pdf。

来源 Issue #394
故障排除
当使用 numpy >= 2.0 与 docling 或混合库时,为什么会出错?

该项目已原生支持 numpy >= 2.0(已在 lockfiles 中使用 numpy 2.2.6/2.4.2 验证)。如果遇到错误,很可能是由于之前固定了 numpy < 2 的传递依赖项(如 docling 或 easyocr)的陈旧安装所致。要修复,请重新彻底安装:pip install --upgrade --force-reinstall docling 或 pip install --no-cache-dir docling[easyocr]。确保所有包都已更新。如果问题仍然存在,请使用 pip list 检查已解析的依赖版本,并报告 traceback、Python version 和安装方法。

来源 Issue #330