1. Go to this page and download the library: Download rust-pdf/rustpdf 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/ */
use RustPdf\{Pdf, SigningOptions};
$pdf = file_get_contents('contract.pdf');
$certDer = file_get_contents('signer-cert.der'); // X.509 (DER)
$signed = Pdf::signWith(
$pdf,
$certDer,
fn (string $toSign): string => $hsm->signRsaSha256($toSign), // key never leaves the HSM
chain: [$intermediateDer],
options: new SigningOptions(reason: 'Approved', pades: true),
);
file_put_contents('contract.signed.pdf', $signed);
$session = Pdf::beginSigning($pdf, new SigningOptions(pades: true));
$container = $hsm->buildCmsContainer($session->getHash()); // raw 32-byte SHA-256
$signed = $session->complete($container); // final signed PDF
sh
php vendor/rust-pdf/rustpdf/bin/rustpdf-install-lib
sh
cargo build -p pdf-ffi
php bindings/php/test/run.php # or: make php-test
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.