Analyze a file
scanfile
POST https://facturalex.com/api/v1/scanfile?login=&password=
| login | Your identification code. |
|---|---|
| password | Your password. |
| multipart/form-data | |
| file | Content of the PDF in binary. |
$ curl -D - -X POST "https://facturalex.com/api/v1/scanfile?login=abcdef&password=ABCDEF" -F "file=@file.pdf"
scanfile returns the result of the analysis of a PDF.
Example for a valid PDF/A-3b which contains a clear text and an XML file named factur-x.sml profile minimum which is syntactically correct:
{"status":"success","data":{"clear_text":true,"xml":"factur-x.xml","xml_profile":"minimum","xml_errors":null,"pdfa_errors":null}}
Example for a PDF which doesn't contain an XML file named factur-x.sml and which is not a valid PDF/A-3b:
{"status":"success","data":{"clear_text":true,"xml":null,"pdfa_errors":["6.2.4.3-2","6.6.2.1-1"]}}
PDF/A-2 and PDF/A-3 validation rules
In case of error, scanfile returns the code HTTP/1.1 400 Bad Request, HTTP/1.1 401 Unauthorized, 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 scanfile.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) {
Defines the function scanfile.
$login is your identification code. $password is your password.
$file is the pathname of the PDF file to validate.
- $curl = 'https://facturalex.com/api/v1/scanfile' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);
Sets $curl to the URL of the scanfile 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 scan 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, scanfile returns false.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- if ($r['status'] != 'success') {
- return false;
- }
Returns false in case of error.
- return $r['data'];
- }
Returns the table of the analysis of the PDF.
EXAMPLE
Assuming you have saved the files sendhttp.php, filemimetype.php and scanfile.php in the current directory, run PHP in interactive mode, load the scanfile function and call it with your identification code and password, the pathname of a PDF in argument:
$ php -a
php > require_once 'scanfile.php';
php > $r=scanfile('abcdef', 'ABCDEF', 'good.pdf');
php > print_r($r);
Array
(
[clear_text] => 1
[xml] => factur-x.xml
[xml_profile] => minimum
[xml_errors] =>
[pdfa_errors] =>
)
php > $r=scanfile('abcdef', 'ABCDEF', 'bad.pdf');
php > print_r($r);
Array
(
[clear_text] => 1
[xml] =>
[pdfa_errors] => Array
(
[0] => 6.2.4.3-2
[1] => 6.6.2.1-1
)
)
php > quit

Comments
To add a comment, click here.