8

Validate a PDF/A

checkpdfa

POST https://tesseractor.com/api/v1/checkpdfa?login=&password=

loginYour identification code.
passwordYour password.
multipart/form-data
fileContent of the PDF in binary.
profileLevel 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"]}}

veraPDF Validation

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:

  1. require_once 'sendhttp.php';
  2. require_once 'filemimetype.php';

Loads the code of the sendpost and file_mime_type functions.

  1. 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'.

  1.     $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.

  1.     $args = array(
  2.         'profile'   => $profile,
  3.     );

Prepares the list of arguments of the POST: profile - the level of conformity to verify.

  1.     $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.

  1.     $response=sendpost($curl, $args, $files);

Sends the HTTP request with sendpost. The arguments login and password are already in $curl.

  1.     if (!$response or $response[0] != 200) {
  2.         return false;
  3.     }

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.

  1.     $r=json_decode($response[2], true);

Decodes the data returned in JSON.

  1.     if ($r['status'] == 'success') {
  2.         return true;
  3.     }

Returns true if the document is a valid PDF/A for the specified level of conformity.

  1.     if ($r['status'] == 'fail') {
  2.         return $r['data']['rules'];
  3.     }

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.

  1.     return false;
  2. }

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.

SEE ALSO

Call the service API, Make a PDF/A, Search for viruses

Comments

To add a comment, click here.