PHP code example of aniketc068 / atick

1. Go to this page and download the library: Download aniketc068/atick library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aniketc068 / atick example snippets



Aniketc068\ATick\Atick;

$signed = Atick::signPfx(
    file_get_contents('doc.pdf'),
    file_get_contents('my.pfx'),
    [
        'password'   => '••••',
        'cn'         => 'Axonate Tech',
        'reason'     => 'Approved',
        'green_tick' => true,
        'page'       => 1,
        'rect'       => [300, 55, 575, 175],
        'pades'      => true, 'timestamp' => true, 'ltv' => true,   // PAdES-B-LT
    ]
);

file_put_contents('signed.pdf', $signed);

Atick::signPfx($pdf, $pfx, $options);        // sign with a .pfx / .p12 / .pem (auto-detected)
Atick::prepare($pdf, $options);              // deferred / eSign: returns [$prepared, $bytesToSign]
Atick::cmsPfx($data, $pfx, $options);        // detached CMS over data
Atick::embed($prepared, $cms);               // embed a detached CMS into a prepared PDF
Atick::prepareFields($pdf, $options);        // make an empty signature field (template)
Atick::signField($pdf, $pfx, $options);      // sign an existing empty field
Atick::setMetadata($pdf, $options);          // Title / Author / Subject / Keywords / …
Atick::addDocTimestamp($pdf, $options);      // archive DocTimeStamp (PAdES-B-LTA)
Atick::setFastSigning(true | false);         // revocation-cache toggle
Atick::decrypt($pdf, $password);             // decrypt a password-protected PDF
Atick::version();                            // engine version

['green_tick' => true]      // the "?" mark — Adobe paints it GREEN for valid+trusted, RED if invalid
['always_check' => true]    // the green-tick graphic as the base
['green_tick' => false]     // no mark — a plain signature

[$prepared, $bytesToSign] = Atick::prepare($pdf, [
    'cn' => 'DS TEST', 'reason' => 'eSign',
    'placements' => [[1, [300, 55, 575, 175]]], 'contents_size' => 16384,
]);

// the eSign InputHash is the SHA-256 of $bytesToSign:
$inputHash = hash('sha256', $bytesToSign);
// ... sign with your provider / eSign ESP, get back a detached CMS ...

$signed = Atick::embed($prepared, $cms);

Atick::signPfx($pdf, $pfx, ['pades' => true]);                                            // B-B
Atick::signPfx($pdf, $pfx, ['pades' => true, 'timestamp' => true]);                       // B-T
Atick::signPfx($pdf, $pfx, ['pades' => true, 'timestamp' => true, 'ltv' => true]);        // B-LT
Atick::signPfx($pdf, $pfx, ['pades' => true, 'timestamp' => true, 'lta' => true]);        // B-LTA

use Aniketc068\ATick\AtickException;

try {
    Atick::signPfx($pdf, $pfx, ['password' => 'wrong']);
} catch (AtickException $e) {
    error_log('signing failed: ' . $e->getMessage());
}