docparser-sdk 0.1.0

docparser 一体化入口:一次依赖拿到 core + PDF + Office 后端,输出统一 IR
Documentation
# docparser-sdk


docparser 的**一体化入口**:一次依赖拿到 `docparser-core` + PDF + Office 后端,直接输出统一 IR / Markdown / JSON。

## 安装


```bash
cargo add docparser-sdk                       # 默认含 pdf + office + epub
cargo add docparser-sdk --no-default-features  # 只要核心 + 纯文本(txt/md/csv/html)
```

特性(默认全开):

| feature | 默认 | 内容 |
| --- | --- | --- |
| `md` / `csv` / `html` | ✅ | 透传 `docparser-core` 的文本族插件 |
| `pdf` | ✅ | `docparser-pdf`(PDFium worker + pdf-extract 兜底) |
| `epub` | ✅ | `docparser-epub`(EPUB2/3,按标题自适应分章) |
| `office` | ✅ | `docparser-office` 三格式(= `docx` + `xlsx` + `pptx`) |
| `docx` / `xlsx` / `pptx` | ✅(随 `office`) | 单格式:只编译一种解析器 |

### 按需引用(体积从大到小的实际接法)


```bash
# 只要 Word(不编译 PDF / Excel / PPT / EPUB)→ 依赖 31 个,rlib 约 0.5 MB

cargo add docparser-sdk --no-default-features --features docx

# 只要 PDF → 依赖 114 个(PDFium 绑定 + 图像栈,重在这一层)

cargo add docparser-sdk --no-default-features --features pdf

# 不要任何二进制格式,只要文本族 → 依赖 9 个

cargo add docparser-sdk --no-default-features --features md,csv,html

# 裸内核(IR + 引擎 + txt)→ 依赖 9 个

cargo add docparser-sdk --no-default-features
```

参考实测(Windows / rustfmt 无关,`--release`):

| 组合 | 依赖数 | `rlib` |
| --- | --- | --- |
| `docparser-core`(裸内核) | 9 | 1.03 MB |
| `docparser-core` + 文本族 | 9 | 1.18 MB |
| `docparser-office` 只 `docx` | 26 | 0.49 MB |
| `docparser-office` 三格式 | 26 | 0.94 MB |
| `docparser-epub` | 21 | — |
| `docparser-pdf` | 103 | — |
| `docparser-sdk` 只 `docx` | 31 | — |
| `docparser-sdk` 全量 | 117 | — |

依赖数用 `cargo tree -p <crate> --no-default-features --features <…> --edges normal --prefix none`
去重统计;PDF 那 103 个绝大多数是 `pdfium-render` / `image` 的传递依赖,裁不掉。

**最终二进制差多少**:同一个 `fn main` 只调 `docparser_sdk::parse`,`--release` 产物在 Windows 上
`features = ["docx"]` 是 **0.43 MB**,默认全量是 **4.06 MB**(差 3.6 MB,几乎全在 PDFium 绑定与
图像栈)。命令行工具 `docparser-cli`(全格式 + clap + serde_json)为 4.69 MB。

## 用法


```rust
// 开箱即用:内置后端已注册
let doc = docparser_sdk::parse("report.pdf")?;
println!("{} pages", doc.pages.len());

let md = docparser_sdk::parse_markdown("spec.docx")?;
let json = docparser_sdk::parse_json("sheet.xlsx")?;

// 需要定制后端链 / 超时 / OCR 时
let engine = docparser_sdk::engine_with(docparser_sdk::BackendPolicy {
    enable_ocr: true,
    max_pages: 50,
    ..Default::default()
});
let doc = engine.parse("scanned.pdf")?;
```

底层 crate 通过重导出随时可达:`docparser_sdk::core::…`、`docparser_sdk::pdf::…`、
`docparser_sdk::office::…`、`docparser_sdk::epub::…`。
需要自定义后端时实现 `core::plugin::ParseCapability` / `FormatPlugin` 并注册到
`core::Registry`,行为与内置后端完全等价。

## 运行时依赖


PDF 需要 PDFium 动态库(`DOCPARSER_PDFIUM_LIB` 或 `<exe>/../lib/`),
扫描件需要 `docparser-ocr` 可执行文件与模型目录。详见 `docparser-pdf` 的 README。

## 许可


MIT OR Apache-2.0