firecrawl/anydoc · 上手攻略

  • 仓库:firecrawl/anydoc
  • 链接:https://github.com/firecrawl/anydoc
  • 分类:文档处理 · Rust 工具 · AI 数据准备
  • 作者:Tom
  • 更新:2026-08-06

这是什么

anydoc 是 Firecrawl(知名网页抓取工具团队)开源的 Rust 文档转换库,专注将各类办公文档(Word、Excel、PowerPoint、PDF、EPUB、CSV、RTF、OpenDocument 等 14 种格式)统一转为干净的 GitHub-Flavored Markdown,中间位数延迟低于 5ms。

它不跑 ML 模型,不调外部 OCR 服务,纯 Rust 实现,有 Node.js、Python、WASM 四套语言绑定。设计目标是让 AI agent 能原生"读懂"各种格式的文档内容,把文档变成 LLM-ready 的结构化文本。


解决什么问题

在 AI 数据处理流水线中,最烦的不是模型不够强,而是文档格式太乱。PDF 抽不出文字、Word 样式丢失、Excel 转 CSV 乱码——这些问题是 data engineering 的日常痛点。

anydoc 的核心价值: - 格式全覆盖:14 种格式统一进、Markdown 统一出,一套逻辑处理所有类型 - 输出稳定:同一 Markdown 序列化器处理所有格式,加粗、表格、列表、代码块、注脚行为完全一致 - 速度快:Rust 实现,中位延迟 <5ms,比 LibreOffice(~1129ms)快 200 倍 - 结构保留完整:标题层级、表格合并单元格、编号列表原始序号、PPT 演讲者备注,均保留


快速安装

Node.js(npm,含 WASM 浏览器版)

# CLI(自动下载平台对应二进制)
npx @firecrawl/anydoc report.docx

# 全局安装 CLI
npm install -g @firecrawl/anydoc

# Node.js 库
npm install @firecrawl/anydoc

# 浏览器 WASM 版
npm install @firecrawl/anydoc-wasm

Python

pip install firecrawl-anydoc

Rust(直接用 Cargo)

[dependencies]
anydoc = "1"

Agent Skill 方式(Claude Code / Codex 等通用)

npx skills add firecrawl/anydoc

⚠️ Python 绑定版本需确认:pypi 上包名为 firecrawl-anydoc,非 anydoc。Rust crate 名为 anydoc


核心用法

CLI 命令行

# 文件转 Markdown 输出到 stdout
npx @firecrawl/anydoc report.docx

# 输出到文件
npx @firecrawl/anydoc slides.pptx -o slides.md

# 读 stdin(CSV 场景)
npx @firecrawl/anydoc - --format csv < data.csv > data.md

# 查看所有选项
npx @firecrawl/anydoc --help

Python API

import anydoc

# 从文件路径转换
markdown = anydoc.to_markdown("report.docx")

# 从字节流(自动识别格式)
markdown = anydoc.to_markdown_bytes(data)

# CSV 等无签名格式需显式指定
markdown = anydoc.to_markdown_bytes(data, "csv")

# 保留嵌入资源(图)到 document 模型
document = anydoc.to_document(data)
# document.images 里有各图片原始字节与 MIME type

Node.js API

import { toMarkdown, toMarkdownBytes, toDocument } from '@firecrawl/anydoc';

// 从文件路径
const md = await toMarkdown('report.docx');

// 从字节流
const md = await toMarkdownBytes(bytes);

// 保留图片等资源
const doc = await toDocument(bytes);
// doc.assets 里有各嵌入资源的字节数据

Rust API

use anydoc::{to_markdown, to_markdown_bytes, to_document, Format};

let md = to_markdown("report.docx")?;
let md = to_markdown_bytes(&bytes, None)?;
let md = to_markdown_bytes(&bytes, Some(Format::Csv))?;
let doc = to_document(&bytes, None)?;

典型适用场景

  1. RAG 数据预处理:将 PDF/Word 合同、报告批量转 Markdown,构建向量知识库
  2. AI Agent 文档读取:Agent Skill 安装后直接读用户上传的 .docx/.xlsx,Claude Code / Codex 原生理解办公文件
  3. 数据迁移管道:旧系统导出的 .doc/.xls 文件转结构化文本,用于大模型分析
  4. PPT 笔记提取:将 PowerPoint 演讲稿转 Markdown,快速提取演讲者备注

坑与注意

坑点 说明
PDF 纯图片扫描页无法识别 anydoc 的 PDF 解析基于文本层,扫描件(无文字层)会输出空白;Firecrawl 托管 API 有 OCR 模型处理这类情况
CSV 无文件签名 CSV 是纯文本流,格式靠内容检测不够可靠,README 建议显式指定 --format csv
Python 包名不是 anydoc pypi 上是 firecrawl-anydoc,直接 pip install anydoc 会装到别的包
.doc(旧版 Word)支持有限 评测中 .doc 得分(87)低于 .docx(86),旧格式建议先转 .docx 再处理
加密文件无法处理 密码保护的 Office 文档会直接失败,需先解密

与同类对比

工具 支持格式数 中位延迟 输出质量评分 说明
anydoc 14 4.4ms 94 Rust,无外部依赖,速度最快
LibreOffice 12 1129ms 87 通用办公软件,依赖重,适合复杂格式保真
unstructured 8 573ms 58 Python 库,ML 驱动,适合非结构化数据
markitdown 6 135ms 33 轻量,但支持格式少
pandoc 5 102ms 34 通用文档转换,可做格式互转,但非专为 LLM 设计
docling 4 514ms 21 专注 PDF 深度解析,但速度慢
mammoth 1 53ms 8 仅支持 .docx,简单场景够用

结论:anydoc 在格式覆盖、速度、输出质量三个维度同时领先,最适合作为 AI 数据流水线的入口。复杂 Word 格式保真场景可考虑加一层 LibreOffice 后处理。


一句话推荐结论

anydoc 是目前将办公文档转 LLM 可读 Markdown 的最优选择——14 格式全覆盖、5ms 级延迟、Rust 原生实现,AI 数据准备管道必装。


最小可跑命令

# Node.js 环境
npm install -g @firecrawl/anydoc
npx @firecrawl/anydoc ./test.docx -o test.md
cat test.md

# Python 环境
pip install firecrawl-anydoc
python -c "import anydoc; print(anydoc.to_markdown('test.docx'))"

硬件/版本备注:Rust 二进制跨平台,支持 macOS/Linux/Windows;Python 3.8+;Node.js 18+。PDF 扫描件识别需补充 OCR 步骤(如 Tesseract 或 Firecrawl 托管 API)。


原始链接:https://github.com/firecrawl/anydoc | 无特定 commit SHA 引用,v1.x 版本。