PHP code example of jkudish / laravel-document-extraction

1. Go to this page and download the library: Download jkudish/laravel-document-extraction 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/ */

    

jkudish / laravel-document-extraction example snippets


use Jkudish\DocumentExtraction\Facades\Extraction;

Extraction::fromPath($path);
Extraction::fromStorage($path, disk: 'documents');
Extraction::fromUpload($uploadedFile);
Extraction::fromStream($stream, mimeType: 'text/plain');
Extraction::fromString($contents, mimeType: 'application/json');

$result = Extraction::fromStorage('inbox/letter.pdf')->text();

$text = $result->text;

$result = Extraction::fromPath($path)
    ->withoutAi()
    ->text();

use Illuminate\Contracts\JsonSchema\JsonSchema;

$result = Extraction::fromStorage('inbox/invoice.pdf')
    ->instructions('Extract only facts present in the invoice.')
    ->schema(fn (JsonSchema $schema) => [
        'invoice_number' => $schema->string()->nullable()->

$result = Extraction::fromPath($path)
    ->using(PurchaseDocumentAgent::class)
    ->extract();

$result = Extraction::fromPath($path)
    ->detectDocuments()
    ->schema(fn (JsonSchema $schema) => [
        'reference' => $schema->string()->nullable()->

$result = Extraction::fromPath($path)->text(
    provider: 'openai',
    model: 'gpt-5.6-luna',
);

use Jkudish\DocumentExtraction\Exceptions\ExtractionException;

try {
    $result = Extraction::fromPath($path)->text();
} catch (ExtractionException $exception) {
    $code = $exception->errorCode;
    $partial = $exception->partialResult;
}

use Jkudish\DocumentExtraction\ExtractionInvocation;
use Jkudish\DocumentExtraction\Facades\Extraction;

Extraction::fake(fn (ExtractionInvocation $invocation) => $expectedResult);

$result = Extraction::fromPath('/not/read/by/the/fake.pdf')->text();

Extraction::assertCalled(fn (ExtractionInvocation $invocation) =>
    $invocation->source->reference() === '/not/read/by/the/fake.pdf'
);
sh
php artisan vendor:publish --tag=document-extraction-config
php artisan extraction:doctor