文档标题

这里是正文内容...

【免费下载链接】docling Get your documents ready for gen AI 【免费下载链接】docling 项目地址: https://gitcode.com/GitHub_Trending/do/docling

表格示例

列1列2列3
数据1数据2数据3

代码块示例

def example_function():
    return "Hello Docling"

图片描述

图片描述


### JSON结构化输出

docling的JSON输出包含丰富的结构化信息:

```json
{
  "metadata": {
    "title": "文档标题",
    "author": "作者",
    "creation_date": "2024-01-01"
  },
  "content": [
    {
      "type": "heading",
      "level": 2,
      "text": "章节标题",
      "confidence": 0.95
    },
    {
      "type": "paragraph", 
      "text": "段落内容",
      "confidence": 0.92
    },
    {
      "type": "table",
      "rows": [
        {"cells": ["标题1", "标题2"]},
        {"cells": ["数据1", "数据2"]}
      ]
    }
  ]
}

🔧 配置选项详解

管道选项配置

from docling.datamodel.pipeline_options import PipelineOptions
from docling.document_converter import DocumentConverter

# 自定义处理选项
pipeline_options = PipelineOptions()
pipeline_options.do_ocr = True           # 启用OCR
pipeline_options.do_layout = True        # 启用布局分析
pipeline_options.do_tables = True        # 启用表格识别

converter = DocumentConverter(pipeline_options=pipeline_options)
result = converter.convert("document.pdf")

OCR引擎选择

from docling.datamodel.pipeline_options import PipelineOptions, EasyOcrOptions

pipeline_options = PipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.ocr_options = EasyOcrOptions()  # 使用EasyOCR引擎

converter = DocumentConverter(pipeline_options=pipeline_options)

🚨 常见问题处理

错误处理示例

from docling.document_converter import DocumentConverter
from docling.exceptions import DoclingConversionError

try:
    converter = DocumentConverter()
    result = converter.convert("invalid_file.txt")
    print("转换成功!")
except DoclingConversionError as e:
    print(f"转换错误: {e}")
except FileNotFoundError:
    print("文件不存在")
except Exception as e:
    print(f"未知错误: {e}")

性能优化建议

# 禁用不需要的功能提升性能
pipeline_options = PipelineOptions()
pipeline_options.do_ocr = False          # 如果不是扫描文档
pipeline_options.do_layout = False       # 如果不需要布局分析
pipeline_options.do_tables = False       # 如果不需要表格识别

converter = DocumentConverter(pipeline_options=pipeline_options)

📊 使用场景对比

场景类型推荐配置输出格式注意事项
简单文本提取默认选项Markdown处理速度快,资源消耗低
扫描文档处理启用OCRMarkdown/JSON需要安装Tesseract
结构化数据提取启用表格识别JSON保留表格结构信息
学术论文处理全功能启用Markdown支持公式和参考文献

🎯 最佳实践总结

  1. 安装验证:安装后运行简单测试确认功能正常
  2. 格式选择:根据下游应用选择合适的输出格式
  3. 错误处理:添加适当的异常处理机制
  4. 性能调优:根据需求禁用不必要的功能模块
  5. 批量处理:使用CLI进行大规模文档处理

验证安装成功

# 简单测试脚本
from docling.document_converter import DocumentConverter

def test_installation():
    try:
        converter = DocumentConverter()
        print("✅ docling安装成功!")
        return True
    except Exception as e:
        print(f"❌ 安装存在问题: {e}")
        return False

if __name__ == "__main__":
    test_installation()

【免费下载链接】docling Get your documents ready for gen AI 【免费下载链接】docling 项目地址: https://gitcode.com/GitHub_Trending/do/docling

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值