Make a PDF/A
makepdfa
POST https://tesseractor.com/api/v1/makepdfa?login=&password=
login | Your identification code. |
---|---|
password | Your password. |
multipart/form-data | |
file | Content of the PDF or JPG, PNG or GIF image in binary. |
profile | Level of conformity. |
Set profile
to 1b
, 2b
or 3b
.
$ curl -D - -X POST "https://tesseractor.com/api/v1/makepdfa?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/v1/checkpdfa?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:
- require_once 'sendhttp.php';
- require_once 'filemimetype.php';
Loads the code of the sendpost
and file_mime_type
functions.
- 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'
,
$output
is the pathname of the PDF/A in output.
- $curl = 'https://tesseractor.com/api/v1/makepdfa' . '?' . 'login=' . urlencode($login) . '&' . 'password=' . urlencode($password);
Sets $curl
to the URL of the makepdfa 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 required level of conformity.
- $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.
- $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, makepdfa
returns false.
- return @file_put_contents($output, $response[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
Comments
To add a comment, click here.