Quickly and easily connect to Mindee's API services using PHP.
Here's the TL;DR of getting started.
First, get an API Key
If you do not have them, you'll need the following packages on your system:
- php-curl
- php-json (not necessary for versions >= 8.0.0)
- php-fileinfo
Then, install this library:
composer require mindee/mindee
Finally, PHP away!
<?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:
$inputDoc = $mindeeClient->sourceFromFile($myFile);
A URL (HTTPS
only):
$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:
$inputDoc = $mindeeClient->sourceFromB64($myInputString, "my-file-name.ext");
Raw bytes, making sure to specify the extension of the file name:
$inputDoc = $mindeeClient->sourceFromBytes($myRawBytesSequence, "my-file-name.ext");
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);
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);
Some features such as Invoice Splitter auto-extraction & Multi Receipts auto-extraction require the ImageMagick library, which in turn requires GhostScript.
ImageMagick is usually bundled with most installations. If not, you can install it using your distribution's package manager.
More details here.
Ghostscript can be installed from the website download page, or if using an apt compatible distribution:
sudo apt-get update
sudo apt-get install -y ghostscript
In some cases, you might also want to authorize the ImageMagick policy to edit PDF files:
DQT='"'
SRC="rights=${DQT}none${DQT} pattern=${DQT}PDF${DQT}"
RPL="rights=${DQT}read|write${DQT} pattern=${DQT}PDF${DQT}"
sudo sed -i "s/$SRC/$RPL/" /etc/ImageMagick-6/policy.xml
Brew will be required for this install.
brew update
brew install imagemagick
pecl install imagick # Might not be needed in some instances. Do not try to install before installing PHP & Pecl.
You can install Ghostscript by downloading it, or simply by using Chocolatey.
choco install ghostscript --version 10.03.1 -y
gs
alias might not be available by default, but it is possible to bind it fairly simply by either adding gswin32c.exe
or gswin64c.exe
to your $PATH
and then adding a symlink in powershell using:
New-Item -ItemType SymbolicLink -Path "C:\Windows\gs.exe" -Target "C:\Program Files\gs\gs10.03.1\bin\gswin64c.exe"
New-Item -ItemType SymbolicLink -Path "C:\Windows\gs" -Target "C:\Program Files\gs\gs10.03.1\bin\gswin64c.exe"
Complete details on the working of the library are available in the following guides:
- Getting started
- PHP Command Line Interface (CLI)
- PHP Generated APIs
- PHP Custom APIs (API Builder - Deprecated)
- PHP Invoice OCR
- PHP Receipt OCR
- PHP Financial Document OCR
- PHP Passport OCR
- PHP Resume OCR
- PHP Proof of Address OCR
- PHP International Id OCR
- PHP EU License Plate OCR
- PHP EU Driver License OCR
- PHP FR Bank Account Detail OCR
- PHP FR Carte Grise OCR
- PHP FR Carte Vitale OCR
- PHP FR ID Card OCR
- PHP US Bank Check OCR
- PHP US W9 OCR
- PHP US Driver License OCR
- PHP Barcode Reader API
- PHP Cropper API
- PHP Invoice Splitter API
- PHP Multi Receipts Detector API
You can view the source code on GitHub.
You can also take a look at the Reference Documentation.
Copyright © Mindee
Available as open source under the terms of the MIT License.