Make a PDF/A

makepdfa

POST https://tesseractor.com/api/makepdfa?version=1&login=&password=

versionVersion number of the API.
loginYour identification code.
passwordYour password.
multipart/form-data
fileContent of the PDF or JPG, PNG or GIF image in binary.
profileLevel of conformity.

version is 1.

profile is '1b', '2b' or '3b'>.

fox.jpg

$ curl -D - -X POST "https://tesseractor.com/api/makepdfa?version=1&login=abcdef&password=ABCDEF" -F "profile=2b" -F "file=@fox.jpg" -o pdfa.pdf

Display the PDF/A:

$ evince pdfa.pdf

Check the PDF/A:

curl -s --fail --show-error -X POST "https://tesseractor.com/api/checkpdfa?version=1&login=abcdef&password=ABCDEF" -F "profile=2b" -F "file=@pdfa.pdf"
{"status":"success","data":null}

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 makepdfa.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 makepdfa($login, $password, $file, $profile='2b', $output='pdfa.pdf') {

Defines the function makepdfa. $login is your identification code. $password is your password. $file is the pathname of the PDF, JPEG, PNG or GIF file to convert. $profile is the required level of conformity, i.e. '1b', '2b' or '3b', $file is the pathname of the PDF/A in output.

  1.     $curl = 'https://tesseractor.com/api/makepdfa?version=1' . '&login=' . urlencode($login) . '&password=' . urlencode($password);

Sets $curl to the URL of the makepdfa action with the version number of the API, 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 required level of conformity.

  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, JPEG, PNG or GIF to convert 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 version, 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, makepdfa returns false.

  1.     return @file_put_contents($output, $response[2]);
  2. }

Returns true if the content of the PDF/A could be written to the output file, false otherwise.

EXAMPLE

Assuming you have saved the files sendhttp.php, filemimetype.php and makepdfa.php in the current directory, run PHP in interactive mode, load the makepdfa function and call it with your identification code and password, the pathname of a PDF, JPEG, PNG or GIF file and a level of conformity in argument:

$ php -a
php > require_once 'makepdfa.php';
php > makepdfa('abcdef', 'ABCDEF', 'file.pdf', '2b');
php > quit

Display the PDF/A:

$ evince pdfa.pdf
SEE ALSO

Call the service API

Comments

To add a comment, click here.