零 OCR 依赖!Firecrawl 这个 Rust 库把 Word / PPT / Excel 全变成 Markdown

Firecrawl AnyDoc 是一个纯 Rust 实现的开源库,支持 Word、PPT、Excel、PDF 等 14 种办公文档格式直接转换为 GitHub Flavored Markdown,无需 OCR、不依赖 ML 模型、不调用外部服务。其核心优势在于零 OCR 依赖、跨平台预编译 CLI、多语言绑定(Node.js/Python/WASM/Rust)及合规友好的纯前端转换能力,适用于 RAG 知识库构建与文档批量预处理。

01 引言

做过知识库的同学都懂:文档转 Markdown,最折磨人的不是格式,是 OCR。

为了几张扫描页装 Tesseract,中文字库配半天;换 PaddleOCR,显存又不够;干脆调云 OCR API,按页计费,几百份文档跑下来账单吓一跳。就算文档本身是纯文本的,你也会被整套 OCR 依赖链绑架——装包、配模型、管密钥,一个都跑不掉。

所以看到 Firecrawl 开源的 anydoc 时,我最先盯上的不是"14 种格式",也不是"4.4ms",而是 README 里那句:Pure Rust, no ML models, no external services。翻译过来就是——零 OCR 依赖,装完直接用,不联网、不加载模型、不掏钱。

02 项目简介

anydoc 是 Firecrawl 开源的纯 Rust 库,把 Word / PPT / Excel / ODF / RTF / EPUB / CSV / PDF 共 14 种格式统一转成 GFM Markdown,MIT 协议,也是 Firecrawl Parse 的底层引擎。

所有格式先解析进同一个 Document 中间模型(blocks / inlines / tables / footnotes / assets),再走同一个 GFM 序列化器——所以修一次表格转义 bug,全部格式受益。PDF 是特例,走自家的 pdf-inspector 直出 Markdown。格式识别靠字节内容标记而非扩展名,改错后缀照样转对。

官方基准 100 份真实文档、14 种格式,中位耗时 4.4ms,质量分 81(均为第一)。对比 LibreOffice 1129.5ms、pandoc 102.1ms、markitdown 134.8ms。数据有前提——项目方自测、语料未公开、LLM 判官评分,但数量级差距可信。

支持的格式一览:

类别扩展名
Word.doc、.docx、.docm
PowerPoint.ppt、.pps、.pot、.pptx、.pptm、.ppsx、.ppsm
Excel.xls、.xlsx、.xlsm、.xlsb
OpenDocument.odt、.ods、.odp
RTF.rtf
EPUB.epub
CSV.csv
PDF.pdf

GitHub地址:https://github.com/firecrawl/anydoc

官网地址:https://firecrawl.github.io/anydoc/

03 安装

官方提供了多种安装方式。

3.1 CLI

不写任何代码,直接把文档转成 Markdown 输出到终端或文件。前面几步完全不碰 OCR。

# 输出到 stdout
npx @firecrawl/anydoc report.docx

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

# 从标准输入读,CSV 这种没魔数的要显式指定格式
npx @firecrawl/anydoc - --format csv < data.csv

# 只有遇到扫描件时,才 opt-in 走托管 OCR
npx @firecrawl/anydoc scan.pdf --ocr hosted

npx 首次运行会自动下载对应平台的预编译二进制。要常驻命令就 npm install -g @firecrawl/anydoc,然后用 anydoc --help 看全部选项。Markdown 走 stdout,错误走 stderr,管道友好。

3.2 Node.js

服务端集成首选。文件路径或字节流转 Markdown,异步不阻塞事件循环,带完整 TypeScript 类型。

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

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

// opt-in OCR(官方 README 示例漏了右花括号,正确写法如下)
const markdownWithOcr = await toMarkdown('report.docx', { ocr: 'hosted' });

// 从字节转,格式由内容自动识别
const fromBytes = await toMarkdownBytes(bytes);

// CSV 没有魔数,需要显式告诉它格式
const fromCsv = await toMarkdownBytes(bytes, 'csv');

// 只要中间模型(里面带着嵌入资源)
const document = await toDocument(bytes);

通过JS可以直接调用,也可以做成网页。

3.3 Python

在 Python 数据管道里转换,转换期间释放 GIL,多线程不受影响,自带类型 stub。

pip install firecrawl-anydoc
import anydoc

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

# opt-in OCR,parse_mode 可选 auto / fast / ocr
markdown = anydoc.to_markdown("scan.pdf", ocr="hosted", parse_mode="ocr")

# 从字节转,自动嗅探格式
markdown = anydoc.to_markdown_bytes(data)

# CSV 需要显式给格式
markdown = anydoc.to_markdown_bytes(data, "csv")

# 拿中间模型,embedded assets 在里面
document = anydoc.to_document(data)

3.4 浏览器 / WASM

纯前端转换,连 OCR 服务都不存在——文件全程在浏览器里,适合合规敏感场景。

npm install @firecrawl/anydoc-wasm
import init, { toMarkdownBytes, toDocument } from '@firecrawl/anydoc-wasm';

await init();  // 必须先初始化 WASM

const markdown = toMarkdownBytes(bytes);
const fromCsv = toMarkdownBytes(bytes, 'csv');
const document = toDocument(bytes);

WASM 版本是同步 API(转换那一步没有 await),别跟 Node 版搞混。

3.5 Rust

嵌进 Rust 服务,零网络调用,极致性能。

cargo add anydoc
let markdown = anydoc::to_markdown("report.docx")?;
let markdown = anydoc::to_markdown_bytes(&bytes, None)?;
let markdown = anydoc::to_markdown_bytes(&bytes, anydoc::Format::Csv)?;
let document = anydoc::to_document(&bytes, None)?;

Rust crate 没有 ocr 选项,也永远不会发起网络请求。真要 OCR,得在 Rust 之外自己接服务——这是刻意保持的纯净边界。

3.6 Agent Skill

让 AI 自己会转文档。给智能体装一个技能,遇到办公文档自动用 anydoc CLI 转换。

npx skills add firecrawl/anydoc

技能定义在 skills/convert-documents-to-markdown/SKILL.md,兼容 Claude Code、Codex、Cursor、OpenCode 等遵循 agentskills.io 协议的客户端。

04 实战

最简单的安装方式就是直接丢给Agent,直接作为skill使用。我们这里演示可以直接使用官方提供的演示界面,也及官网的首页:https://firecrawl.github.io/anydoc/

4.1 pdf测试

源文件:

转化后会直接显示识别的文字:

转化后的结果:

格式错乱不可避免,但是文字识别基本无误。这对知识库的建立提供了良好的基础。

4.2 word测试

word的转化还是相当感人的,保持了基本的格式。

4.3 ppt测试

05 小结

虽然还有很多转化为markdown文档的工具,但零 OCR 依赖,绝对是 anydoc 最被低估的优势。RAG 知识库入库、文档批量预处理、需要保留标题层级和表格结构的内容迁移、对延迟敏感或合规要求高的在线转换,anydoc绝对是一大助力。

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

智_永无止境

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

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

抵扣说明:

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

余额充值
⌂ 换网址