1. Go to this page and download the library: Download dskripchenko/php-pdf-pkcs11 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/ */
dskripchenko / php-pdf-pkcs11 example snippets
use Dskripchenko\PhpPdf\Pdf\Signature\PdfSigner;
use Dskripchenko\PhpPdf\Pdf\SignatureConfig;
use Dskripchenko\PhpPdfPkcs11\Pkcs11Signer;
$signer = Pkcs11Signer::open(
'/usr/lib/softhsm/libsofthsm2.so', // the vendor's PKCS#11 library
pin: $pin,
token: 'signing', // token label, when there are several
keyLabel: 'pdf', // or keyId: '01'
);
$signed = PdfSigner::fromBytes($pdf)
->addField('signature', page: 0, x: 60, y: 450, width: 250, height: 75, appearance: $stamp)
->sign(new SignatureConfig(signer: $signer, timestampAuthority: $tsa));
$token = new PhpPkcs11Token($module, $pin, tokenLabel: 'signing');
// per document
$signer = Pkcs11Signer::fromToken($token, keyLabel: 'pdf');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.