Skip to content

About

可以使得AI进行更有效快速的阅读,文件涵盖了doc,pdf,xlsx等大部分文件格式。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

📚 Document Reader — 文档速读工具链

按扩展名自动选最优工具的本地文档/表格速读工具箱,一次命令批量提取文本与数据。

中文文档 · MIT License

✨ 功能特性

  • 全格式速读:.doc .docx .pdf .xlsx .xls .csv 图片(PNG/JPG)文本,一条命令自动分派最优工具
  • 表格速查:xlsx_query.py 细粒度查询(搜索 / 单元格 / 行列 / 区域 / 转 CSV / SQL 直查)
  • 老格式支持:.xls(老式 Excel)也能读,基于 Rust 引擎 python-calamine
  • SQL 直查:duckdb 直接对表格文件执行 SQL,免导入
  • OCR:RapidOCR 识别图片文字,超宽截图自动放大预处理
  • MarkItDown 增强:复杂 Office/PDF 一键转标准 Markdown
  • 零外部依赖:纯 Python + pip 依赖,无服务器、无云端
  • 可作 WorkBuddy Skill 使用:自带 SKILL.md,放入 ~/.workbuddy/skills/ 即可被 AI 助手自动调用

📁 目录结构

document-reader/
├── README.md          # 本文档
├── SKILL.md           # WorkBuddy Skill 定义(含触发词与工具映射)
├── read_files.py      # 全格式速读脚本
├── xlsx_query.py      # 表格速查脚本(calamine + duckdb)
├── requirements.txt   # Python 依赖清单
└── LICENSE            # MIT 许可证

🛠 安装

# Python 3.10+
pip install -r requirements.txt

可选增强:

pip install 'markitdown[pdf,docx,pptx]'   # 复杂文档转 Markdown
# 系统级工具:antiword(读 .doc 老格式)、pandoc(转 docx)

🚀 快速开始

全格式速读

python read_files.py 报告.pdf                # 提取 PDF 文本
python read_files.py 个人表.doc              # 提取老式 Word
python read_files.py 成绩单.png              # OCR 识别图片
python read_files.py ./资料文件夹            # 批量递归处理整个文件夹
python read_files.py --markitdown 复杂.docx  # 走 MarkItDown 转 Markdown

表格速查

python xlsx_query.py 成绩.xlsx --list                    # 列出所有 sheet
python xlsx_query.py 成绩.xlsx --search "张三"           # 全文搜索,返回坐标
python xlsx_query.py 成绩.xlsx --cell R25C59             # R1C1 引用直查单元格
python xlsx_query.py 成绩.xlsx --row 25 --cols 1-60      # 提取某行指定列
python xlsx_query.py 成绩.xlsx --range A1:F20            # 提取区域
python xlsx_query.py 成绩.xlsx --to-csv 缓存.csv         # 转 CSV(之后 Grep 秒搜)
python xlsx_query.py 成绩.xlsx --sql "SELECT * FROM read_csv_auto('缓存.csv', header=false) WHERE column00='20240001'"

🧭 工具选择策略

场景 推荐工具
普通 PDF / 文字文档 read_files.py(pymupdf 快速提取)
老式 .doc antiword(修改时用 UTF-16LE 二进制等长替换)
复杂排版 Office/PDF --markitdown(MarkItDown 统一转换)
扫描件 / 复杂公式 PDF MinerU(桌面版 GUI / 命令行)
表格查询(单个/几个数) xlsx_query.py --search / --cell
表格高频反复查询 先 --to-csv 转缓存,再 Grep 秒搜
表格聚合统计 / 多表关联 --sql(duckdb 直查)

🔍 技术要点备忘

  • duckdb CSV 列名从 column00 开始(column00=第1列),不是 column1
  • read_xlsx 对含合并单元格表头的文件会推断成单列 → 复杂表头请用原生 --search/--cell
  • 超宽压扁截图(如网页长截图)整图 OCR 效果差 → 先裁剪关键区再放大识别
  • .doc 老格式修改:文本以 UTF-16LE 存储,等长替换最安全

📦 依赖

见 requirements.txt:pymupdf、openpyxl、python-calamine、duckdb、rapidocr-onnxruntime、pillow、markitdown(可选)等。

📄 License

MIT

About

可以使得AI进行更有效快速的阅读,文件涵盖了doc,pdf,xlsx等大部分文件格式。

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages