darlanschmeller/doc-ocr-php
Composer 安装命令:
composer require darlanschmeller/doc-ocr-php
包简介
Document OCR and ingestion pipeline for PHP applications, powered by Mistral AI.
README 文档
README
DocOcr is a lightweight, pipeline-based PHP library that turns documents like PDF, CSV, and XLSX into structured data using Mistral's OCR API.
Designed for:
- Ingestion pipelines
- AI preprocessing
- Finance / accounting docs
- Backend automation
Features
- Supports PDF, CSV, XLSX
- Normalization layer for OCR-friendly input
- OCR powered by Mistral AI
- Extracts structured content (pages, text, tables)
- Fluent pipeline API (
normalize → ocr → toArray) - PHPUnit automated testing
- Custom OCR client injection
Why DocOcr?
Most OCR libraries return raw text blobs. DocOcr focuses on pipeline-friendly, structured extraction designed for backend systems, AI preprocessing, and financial workflows.
It handles:
- File normalization (CSV/XLSX → OCR-friendly layout)
- OCR execution
- Predictable output for downstream processing
Installation
Via Composer (recommended)
composer require darlanschmeller/doc-ocr-php
Include in your project:
require __DIR__ . '/vendor/autoload.php'; use DocOcr\Document;
From source (for development only)
git clone https://github.com/DarlanSchmeller/doc-ocr-php.git
Include in your project:
require __DIR__ . '/src/Document.php'; use DocOcr\Document;
Configuration
Set your Mistral API key in your .env file:
MISTRAL_API_KEY=your_api_key_here MISTRAL_OCR_ENDPOINT=mistral_ocr_endpoint_here # (OPTIONAL) default included
Usage
Basic Usage
$ocr = Document::from(__DIR__ . '<your_file_path>') ->normalize() ->ocr() ->toArray(); $ocrResult = $ocr->getResult();
Injecting your own client instance
If you wish to use a different api key or custom OCR client you may inject it this way:
$client = new MistralOcrClient(new OcrClient('<your_mistral_api_key>')); return Document::fromWithClient(__DIR__ . $fixture, $client) ->normalize() ->ocr() ->toArray();
Pipeline Stages
-
normalize()- Converts CSV and XLSX files into OCR-friendly layouts
- Reads PDFs and images as-is
-
ocr()- Sends the document to Mistral OCR
- Stores the raw OCR response
-
toArray()- Decodes the OCR JSON response into a PHP array
All pipeline stages are idempotent and safe to call multiple times.
Output Example
[ 'pages' => [ [ 'index' => 0, 'markdown' => ' Invoice Number: #20130304 ATTENTION TO: Denny Gunawan 221 Queen St, Melbourne 3000 Total: $39.60 ', 'images' => [], 'tables' => [ [ 'id' => 'tbl-0.html', 'format' => 'html', 'content' => ' Organic Items | Price/kg | Quantity | Subtotal Apple | $5.00 | 1 | $5.00 Orange | $1.99 | 2 | $3.98 ' ] ] ] ] ]
📂 Supported Formats
| Format | Normalized | OCR |
|---|---|---|
| ✅ | ✅ | |
| CSV | ✅ | ✅ |
| XLSX | ✅ | ✅ |
| Images (png, jpg, webp) | ⏭ skipped | ✅ |
Run automated tests
./vendor/bin/phpunit tests
OCR tests are skipped automatically if
MISTRAL_API_KEYis not set.
darlanschmeller/doc-ocr-php 适用场景与选型建议
darlanschmeller/doc-ocr-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 3, 最近一次更新时间为 2026 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「xlsx」 「csv」 「pdf」 「OCR」 「pipeline」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 darlanschmeller/doc-ocr-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 darlanschmeller/doc-ocr-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 darlanschmeller/doc-ocr-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Yii2 export extension
laravel facade to read/write csv file
PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
Collection of tools to use the full power of the Enyalius framework
Alfabank REST API integration
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 37
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-23