PHP code example of lstables / nativephp-mobile-document-scanner

1. Go to this page and download the library: Download lstables/nativephp-mobile-document-scanner library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lstables / nativephp-mobile-document-scanner example snippets


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));
    }
}

$pdfPath = DocumentScanner::scanToPdf();

if ($pdfPath) {
    Storage::put('receipts/scan.pdf', file_get_contents($pdfPath));
}

$pages = DocumentScanner::scanToJpegs(maxPages: 3);

$imagePath = DocumentScanner::scanSinglePage();

$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
);

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
}

$result = DocumentScanner::scanToPdf();

// Move to Laravel storage
Storage::disk('local')->put(
    'documents/scan_' . now()->timestamp . '.pdf',
    file_get_contents($result)
);
bash
php artisan native:plugin:register lstables/nativephp-mobile-document-scanner