Verify an invoice
reportfile
POST https://facturalex.com/api/v1/reportfile?login=&password=
| login | Your identification code. |
|---|---|
| password | Your password. |
| ocr | Extract text with the OCR. |
| resolution | Resolution in dpi of the image generated for each page of a PDF . |
| images | Directly extract just the images in a PDF. |
| multipart/form-data | |
| file | Content of the PDF in binary. |
ocr: 1 - force reading a PDF which contains plain text with the OCR.
Specify the extraction mode of each page of the PDF:
resolution : resolution of the image generated in dpi - 50, 75, 100, 125, 150, 200, 250 or 300 - IMPORTANT: If a page contains only one image and no text, the image is systematically directly extracted from the document,
images : 1 - directly extract only the images.
IMPORTANT: 1 call to reportfile costs 1 credit.
$ curl -D - -X POST "https://facturalex.com/api/v1/reportfile?login=abcdef&password=ABCDEF" -F "file=@file.pdf" > report.pdf
To extract the text of a photocopy:
$ curl -D - -X POST "https://facturalex.com/api/v1/reportfile?login=abcdef&password=ABCDEF" -F "ocr=1" -F "images=1" -F "file=@copyfile.pdf" >report.pdf
reportfile returns the PDF of a report on an invoice compliance analysis.
NOTE: reportfile calls OpenAI which can take some time to respond, between 30 seconds and a bit more than 1 minute.
In case of error, reportfile returns the code HTTP/1.1 400 Bad Request, HTTP/1.1 401 Unauthorized, HTTP/1.1 402 Payment Required, HTTP/1.1 403 Forbidden or HTTP/1.1 500 Internal Error.
USE
Download the code of the sendpost and file_mime_type functions from the iZend library.
Copy the files in the space of your application.
NOTE: See the page Call the service API for a description of the sendpost and file_mime_type functions.
Add the file reportfile.php with the following content:
- require_once 'sendhttp.php';
- require_once 'filemimetype.php';
Loads the code of the sendpost and file_mime_type functions.
- function scanfile($login, $password, $file, $output) {
Defines the function reportfile.
$login is your identification code. $password is your password.
$file is the pathname of the PDF file to verify.
$output is the name of the file which will save the PDF of the report.
- $curl = 'https://facturalex.com/api/v1/reportfile' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);
Sets $curl to the URL of the reportfile action with the identification code and the password of the user's account.
$login and $password must be escaped.
- $files=array('file' => array('name' => basename($file), 'tmp_name' => $file, 'type' => file_mime_type($file)));
Prepares the list of files attached to the POST: file - the PDF to verify with the name of the file, the pathname of the file and its MIME type.
- $response=sendpost($curl, false, $files);
Sends the HTTP request with sendpost.
The arguments login and password are already in $curl.
- if (!$response or $response[0] != 200) {
- return false;
- }
If $response is false, the server is unreachable.
If $response[0] doesn't contain the HTTP return code 200 Ok, an execution error has occurred.
In case of error, reportfile returns false.
- return file_put_contents($output, $response[2]);
- }
Saves the PDF of the report in the file $output.
Returns true if the file has been created properly, false otherwise.
EXAMPLE
Assuming you have saved the files sendhttp.php, filemimetype.php and reportfile.php in the current directory, run PHP in interactive mode, load the reportfile function and call it with as arguments your identification code and password, the pathname of a PDF, the pathname to the file with the output report:
$ php -a
php > require_once 'reportfile.php';
php > $r=reportfile('abcdef', 'ABCDEF', 'file.pdf', 'report.pdf');
php > echo $r ? 'Ok' : 'Ko';
Ok
php > quit
Read the report:
$ evince report.pdf


Comments
To add a comment, click here.