项目简介
LiteParse 是一款独立 PDF 解析工具,提供带边界框的空间文本解析、灵活 OCR 系统,并支持多种输出格式。它本地运行,可集成 Rust、Node.js、Python 及 WASM。
README 预览
# LiteParse\n\n[](https://github.com/run-llama/liteparse/actions/workflows/ci.yml)\n|\n[](https://crates.io/crates/liteparse)\n|\n[](https://www.npmjs.com/package/@llamaindex/liteparse)\n|\n[](https://www.npmjs.com/package/@llamaindex/liteparse-wasm)\n|\n[](https://pypi.org/project/liteparse/)\n|\n[](https://opensource.org/licenses/Apache-2.0)\n|\n[Docs](https://developers.llamaindex.ai/liteparse/)\n\n\n\n> Looking for LiteParse V1? Follow this link to [the old code](https://github.com/run-llama/liteparse/tree/logan/liteparse-v1)\n\nLiteParse is a standalone OSS PDF parsing tool focused exclusively on **fast and light** parsing. It provides high-quality spatial text parsing with bounding boxes, without proprietary LLM features or cloud dependencies. Everything runs locally on your machine.\n\n**Hitting the limits of local parsing?**\nFor complex documents (dense tables, multi-column layouts, charts, handwritten text, or\nscanned PDFs), you'll get significantly better results with [LlamaParse](https://developers.llamaindex.ai/python/cloud/llamaparse/?utm_source=github&utm_medium=liteparse),\nour cloud-based document parser built for production document pipelines. LlamaParse handles the\nhard stuff so your models see clean, structured data and markdown.\n\n> [Sign up for LlamaParse free](https://cloud.llamaindex.ai?utm_source=github&utm_medium=liteparse)\n\n## Overview\n\n- **Fast Text Parsing**: Spatial text parsing using PDFium\n- **Flexible OCR System**:\n - **Built-in**: Tesseract (zero setup, bundled with the library)\n - **HTTP Servers**: Plug in any OCR server (EasyOCR, PaddleOCR, custom)\n - **Standard API**: Simple, well-defined OCR API specification\n- **Screenshot Generation**: Generate high-quality page screenshots for LLM agents\n- **Multiple Output Formats**: JSON and Text\n- **Bounding Boxes**: Precise text positioning information\n- **Multi-language**: Use from Rust, Node.js/TypeScript, Python, or the browser (WASM)\n- **Multi-platform**: Linux, ma
常见问题 (5)
故障排除为什么liteparse返回的TextItem x和y是网格投影坐标而不是PDF点坐标?
在 liteparse v2.0.0-beta.2 中,TextItem.x 和 TextItem.y 被错误地设置为网格投影坐标(字符列和行索引),而非 PDF 点坐标。这是一个已知缺陷。作为临时解决方案,请使用开发者 CLI 工具提取原始 PDF 点坐标:
python -m liteparse.cli extract --pdf-path <your_pdf.pdf>该命令将返回带有正确
x、y、width、height 以及额外元数据的预投影项。团队正在着手永久修复;请关注该仓库的后续版本发布。操作指南如何使用LiteParse在Cloudflare Workers或边缘运行时解析PDF?
使用 @llamaindex/liteparse-wasm 包。它提供了一个基于WebAssembly的PDF解析器,兼容Cloudflare Workers、Deno Deploy、Vercel Edge和浏览器。使用 npm install @llamaindex/liteparse-wasm 安装,并直接导入PDF解析器。查看包的README文件以获取使用示例。原始的依赖Node.js的liteParse包由于原生模块不支持边缘运行时。
故障排除如何修复 LiteParse 在包含原生文本的 PDF 页面上将日语、中文或韩语的 OCR 文本误判为"图表标签"并丢弃的问题?
这是 @llamaindex/liteparse 2.15.0 中的一个 bug。在 crates/liteparse/src/ocr_merge.rs 中,is_chart_label 将所有三个或更少字符的 OCR 词元都视为图表标签。Tesseract 经常将中文、日文和韩文文本切分为一到三个字符的词语,因此 CJK 正文图像会被错误分类。当页面同时包含原生文本时,chart_like_images 随后会丢弃图像 OCR,在设置 LITEPARSE_DEBUG_OCR=1 时显示为 skip(chart-figure)。
修复方法:升级到包含 PR #498 的版本。该修复仅对不包含 CJK 字符的词元应用短词元长度规则,同时保留数字标签检测功能。如果从源码构建,请修补 is_chart_label,使 CJK 词元不会仅仅因为字符数 <= 3 而被标记为标签。
使用以下命令验证:
LITEPARSE_DEBUG_OCR=1 lit parse repro.pdf --ocr-language jpn --format json -q
修复后,CJK OCR 行应显示为 ADD 而不是 skip(chart-figure)。作为临时变通方案,可以在不含原生文本的页面上处理 CJK 图像,或使用已打补丁的构建版本。
故障排除为什么在 Windows 上转换 Office 文档时,`lit parse` 会失败并报错 `Conversion("Command failed: ")`?
在 Windows 上的 lit 2.0.1 中,LibreOffice 用户配置文件 URI 被错误地生成为 file://C:\\Users\\...,但 LibreOffice 要求使用三个斜杠和正斜杠的格式 file:///C:/Users/...。这会导致 soffice 以退出码 1 退出,或者挂起且没有任何 stderr 输出。作为变通方法,请先手动将 Office 文档转换为 PDF,然后再解析该 PDF:
soffice --headless --invisible --convert-to pdf --outdir ./out input.docx
lit parse ./out/input.pdf --format text -o output.md
直接使用 soffice 进行转换之所以可行,是因为它不会使用 lit 生成的格式错误的临时配置文件 URI。
故障排除如何修复使用liteparse OCR时出现的'tessdata/eng.traineddata'错误?
将 TESSDATA_PREFIX 环境变量设置为包含 tessdata 语言文件的目录。
1. 从 https://github.com/tesseract-ocr/tessdata/raw/main/eng.traineddata 下载 eng.traineddata。
2. 将其放在一个文件夹中(例如 Windows 上的 C:\\\\tessdata 或 Linux 上的 /usr/share/tessdata)。
3. 将 TESSDATA_PREFIX 设置为该文件夹路径:
- Windows: $env:TESSDATA_PREFIX='C:\\\\tessdata'
- Linux/macOS: export TESSDATA_PREFIX=/usr/share/tessdata
如果 liteparse 捆绑了 Tesseract,则 tessdata 文件夹可能位于 node_modules/@llamaindex/liteparse/tessdata;请将变量设置为该路径。