Validate a PDF/A
checkpdfa
POST https://tesseractor.com/api/v1/checkpdfa?login=&password=
| login | Your identification code. |
|---|---|
| password | Your password. |
| multipart/form-data | |
| file | Content of the PDF in binary. |
| profile | Level of conformity. |
Set profile to 1a, 1b, 2a, 2b, 2u, 3a, 3b, 3u or 4.
$ curl -D - -X POST "https://tesseractor.com/api/v1/checkpdfa?login=abcdef&password=ABCDEF" -F "profile=2b" -F "file=@fox.pdf"
{"status":"fail","data":{"rules":["6.2.4.3-2","6.6.2.1-1"]}}
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 checkpdfa.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 checkpdfa($login, $password, $file, $profile='2b') {
Defines the function checkpdfa.
$login is your identification code. $password is your password.
$file is the pathname of the PDF file to validate.
$profile is the level of conformity to verify, i.e. '1a', '1b', '2a', '2b', '2u', '3a', '3b', '3u' or '4'.
- $curl = 'https://tesseractor.com/api/v1/checkpdfa' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);
Sets $curl to the URL of the checkpdfa action with the identification code and the password of the user's account.
$login and $password must be escaped.
- $args = array(
- 'profile' => $profile,
- );
Prepares the list of arguments of the POST: profile - the level of conformity to verify.
- $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 validate with the name of the file, the pathname of the file and its MIME type.
- $response=sendpost($curl, $args, $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, checkpdfa returns false.
- $r=json_decode($response[2], true);
Decodes the data returned in JSON.
- if ($r['status'] == 'success') {
- return true;
- }
Returns true if the document is a valid PDF/A for the specified level of conformity.
- if ($r['status'] == 'fail') {
- return $r['data']['rules'];
- }
Returns an array of codes of rules which are not respected if the PDF is not valid PDF/A for the specified level of conformity.
- return false;
- }
Returns false in case of error.
EXAMPLE
Assuming you have saved the files sendhttp.php, filemimetype.php and checkpdfa.php in the current directory, run PHP in interactive mode, load the checkpdfa function and call it with your identification code and password, the pathname of a PDF file and a level of conformity in argument:
$ php -a
php > require_once 'checkpdfa.php';
php > print_r(checkpdfa('abcdef', 'ABCDEF', 'file.pdf', '2b'));
Array
(
[0] => 6.2.4.3-2
[1] => 6.6.2.1-1
)
php > quit
The document is not valid. The rules 6.2.4.3-2 and 6.6.2.1-1 are not respected.

Comments
To add a comment, click here.