1. Go to this page and download the library: Download leapocr/leapocr-php 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/ */
leapocr / leapocr-php example snippets
eapOCR\Enums\Format;
use LeapOCR\Enums\Model;
use LeapOCR\LeapOCR;
use LeapOCR\Models\ProcessOptions;
$client = new LeapOCR((string) getenv('LEAPOCR_API_KEY'));
$job = $client->ocr()->processUrl(
'https://example.com/document.pdf',
new ProcessOptions(
format: Format::STRUCTURED,
model: Model::STANDARD_V2,
schema: [
'type' => 'object',
'properties' => [
'title' => ['type' => 'string'],
],
'
use LeapOCR\Enums\Format;
use LeapOCR\Enums\Model;
use LeapOCR\Models\ProcessOptions;
$job = $client->ocr()->processFile(
__DIR__ . '/sample/test.pdf',
new ProcessOptions(
format: Format::STRUCTURED,
model: Model::STANDARD_V2,
instructions: 'Extract invoice number and total amount',
schema: [
'type' => 'object',
'properties' => [
'invoice_number' => ['type' => 'string'],
'total_amount' => ['type' => 'number'],
],
'
use LeapOCR\Models\PollOptions;
$result = $client->ocr()->waitUntilDone(
$job->jobId,
new PollOptions(
pollIntervalSeconds: 2.0,
maxWaitSeconds: 180.0,
),
);
use LeapOCR\Models\ProcessOptions;
$job = $client->ocr()->processFile(
__DIR__ . '/sample/test.pdf',
new ProcessOptions(templateSlug: 'invoice-template'),
);