# PHP OCR SDK

## Mindee API Helper Library for PHP

Quickly and easily connect to Mindee's API services using PHP.

### Quick Start

Here's the TL;DR of getting started.

First, get an [API Key](https://docs.mindee.com/v1/get-started/create-api-key)

If you do not have them, you'll need the following packages on your system:

* [php-curl](https://www.php.net/manual/en/curl.installation.php)
* [php-json](https://www.php.net/manual/en/json.installation.php) (not necessary for versions >= 8.0.0)
* [php-fileinfo](https://www.php.net/manual/en/fileinfo.installation.php)

Then, install this library:

```shell
composer require mindee/mindee
```

Finally, PHP away!

#### Loading a File and Parsing It

**Global Documents**

```php
<?php

use Mindee\Client;
use Mindee\Product\Invoice\InvoiceV4;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(InvoiceV4::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);
```

**Note:** Files can also be loaded from:

A PHP `File` compatible file:

```php
$inputDoc = $mindeeClient->sourceFromFile($myFile);
```

A URL (`HTTPS` only):

```php
$inputDoc = $mindeeClient->sourceFromUrl("https://files.readme.io/a74eaa5-c8e283b-sample_invoice.jpeg");
```

A base64-encoded string, making sure to specify the extension of the file name:

```php
$inputDoc = $mindeeClient->sourceFromB64($myInputString, "my-file-name.ext");
```

Raw bytes, making sure to specify the extension of the file name:

```php
$inputDoc = $mindeeClient->sourceFromBytes($myRawBytesSequence, "my-file-name.ext");
```

**Region-Specific Documents**

```php
use Mindee\Client;
use Mindee\Product\Us\BankCheck\BankCheckV1;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);
```

**Custom Document (API Builder)**

```php
use Mindee\Client;
use Mindee\Product\Us\BankCheck\BankCheckV1;

// Init a new client
$mindeeClient = new Client("my-api-key");

// Load a file from disk
$inputSource = $mindeeClient->sourceFromPath("/path/to/the/file.ext");

// Parse the file
$apiResponse = $mindeeClient->parse(BankCheckV1::class, $inputSource);

// Print a brief summary of the parsed data
echo strval($apiResponse->document);
```

### Further Reading

You can view the source code on [GitHub](https://github.com/mindee/mindee-api-php).

You can also take a look at the [**Reference Documentation**](https://mindee.github.io/mindee-api-php).

### License

Copyright © Mindee

Available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
