lstables/nativephp-mobile-document-scanner
Composer 安装命令:
composer require lstables/nativephp-mobile-document-scanner
包简介
Document scanning plugin for NativePHP Mobile
README 文档
README
Native document scanning for NativePHP Mobile apps
Scan physical documents from the camera with automatic edge detection, perspective correction, multi-page support, and PDF output. The same scanner engine used by Apple Notes and Google Drive, wrapped in a clean Laravel facade.
Requirements
- PHP 8.2+
- NativePHP Mobile 3.x
- iOS 13.0+ (VisionKit — zero additional dependencies)
- Android API 21+ with at least 1.7 GB RAM (ML Kit via Google Play Services)
Installation
composer require lstables/nativephp-mobile-document-scanner
Register the plugin with NativePHP:
php artisan native:plugin:register lstables/nativephp-mobile-document-scanner
Usage
Basic scan
use lstables\NativeDocumentScanner\Facades\DocumentScanner; $result = DocumentScanner::scan(); if ($result && $result->hasPages()) { // Array of absolute file paths to JPEG pages foreach ($result->pages as $path) { // upload, store, process... } // Combined PDF path (if outputPdf was true) if ($result->hasPdf()) { Storage::put('scans/document.pdf', file_get_contents($result->pdf)); } }
Scan to PDF only
$pdfPath = DocumentScanner::scanToPdf(); if ($pdfPath) { Storage::put('receipts/scan.pdf', file_get_contents($pdfPath)); }
Scan to JPEG pages only
$pages = DocumentScanner::scanToJpegs(maxPages: 3);
Scan a single page
$imagePath = DocumentScanner::scanSinglePage();
Full options
$result = DocumentScanner::scan( maxPages: 10, // 0 = unlimited allowGalleryImport: true, // Android only — allow importing from photo library mode: 'full', // 'base' | 'filter' | 'full' outputPdf: true, // Include a combined PDF outputJpegs: true, // Include per-page JPEGs );
Scanning modes:
| Mode | What it includes |
|---|---|
base |
Crop, rotate, reorder pages |
filter |
+ Greyscale, auto-enhancement filters |
full |
+ ML-powered stain/shadow/finger removal (default) |
Listening to events
Events fire whether you use the facade or the JS bridge, and are received by your Livewire components:
use lstables\NativeDocumentScanner\Events\DocumentScanned; use lstables\NativeDocumentScanner\Events\DocumentScanCancelled; use lstables\NativeDocumentScanner\Events\DocumentScanFailed; #[OnNative(DocumentScanned::class)] public function onScanned(int $pageCount, array $pages, ?string $pdf): void { // Store, upload, or process scanned files } #[OnNative(DocumentScanCancelled::class)] public function onCancelled(): void { // User tapped Cancel } #[OnNative(DocumentScanFailed::class)] public function onFailed(string $reason): void { // Something went wrong }
JavaScript usage
For Livewire + Alpine or SPA setups, use the JS bridge directly:
import { scan, scanToPdf, scanToJpegs, scanSinglePage } from 'vendor/lstables/nativephp-mobile-document-scanner/resources/js/documentScanner' // Full scan const result = await scan({ maxPages: 5, mode: 'full' }) if (result && !result.cancelled) { console.log(result.pages) // ['/path/to/page_1.jpg', ...] console.log(result.pdf) // '/path/to/document.pdf' console.log(result.pageCount) // 5 } // Just a PDF const pdfPath = await scanToPdf() // Just JPEG pages const pages = await scanToJpegs(3) // Single page const page = await scanSinglePage()
ScanResult
| Property | Type | Description |
|---|---|---|
pages |
string[] |
Absolute paths to JPEG files, one per page |
pdf |
string|null |
Absolute path to combined PDF, or null |
pageCount |
int |
Number of pages scanned |
hasPages() |
bool |
Whether any pages were captured |
hasPdf() |
bool |
Whether a PDF was generated |
firstPage() |
string|null |
Path to the first page, or null |
toArray() |
array |
Serialise to plain array |
File locations
Scanned files are written to the device's temporary/cache directory under NativeDocumentScanner/. They persist until the OS clears the cache. Copy them to permanent storage (Laravel's Storage facade, or a file upload) before the session ends.
$result = DocumentScanner::scanToPdf(); // Move to Laravel storage Storage::disk('local')->put( 'documents/scan_' . now()->timestamp . '.pdf', file_get_contents($result) );
Platform notes
iOS
- Uses
VNDocumentCameraViewControllerfrom VisionKit — the same scanner as Apple Notes - No additional dependencies or CocoaPods required
- UI is Apple's — not customisable (this is a system constraint, not a plugin limitation)
- No gallery import available on iOS (camera-only)
Android
- Uses Google ML Kit Document Scanner API via Google Play Services
- ML models are downloaded centrally — minimal impact on app bundle size
- No camera permission required — handled by Play Services
- Gallery import can be enabled via
allowGalleryImport: true - Requires a minimum device RAM of 1.7 GB
Changelog
1.0.0
- Initial release
- VisionKit scanner (iOS)
- ML Kit Document Scanner (Android)
- Facade with
scan(),scanToPdf(),scanToJpegs(),scanSinglePage() DocumentScanned,DocumentScanCancelled,DocumentScanFailedevents- JavaScript bridge library
- Full Pest test suite
License
MIT
lstables/nativephp-mobile-document-scanner 适用场景与选型建议
lstables/nativephp-mobile-document-scanner 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「mobile」 「OCR」 「nativephp」 「document-scanner」 「visionkit」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lstables/nativephp-mobile-document-scanner 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lstables/nativephp-mobile-document-scanner 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lstables/nativephp-mobile-document-scanner 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Beyonic PHP Library
The skeleton application for NativePHP for Mobile.
PHP SDK for Mobile Message SMS API
The Best Image Ocr SDK For BAT.
The Best Image Ocr SDK For BAT.
腾讯 OCR SDK
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-28