Signing a PDF

Signing PDFs digitally can be easily accomplished by providing a certificate and, if necessary, an accompanying private key.

You can easily create a self-signed certificate for testing.

openssl req -x509 -nodes -days 365000 -newkey rsa:2048 -keyout my-certificate.crt -out my-certificate.crt

Then all you need to do, is adding the signature to your HtmlToPdf service as Save handlers.

$html = "Hello World!";
$cert = 'file://'.__DIR__.'/my-certificate.crt';

$signature = new \Typesetsh\HtmlToPdf\Signature($cert);
$signature->ContactInfo = '';
$signature->Location = 'DE';
$signature->Name = 'FooBar';
$signature->Reason = 'Testing';

$service = new \Typesetsh\HtmlToPdf();
$service->saveHandler['signature'] = $signature;
$service->saveHandler['pdf_a'] = new \Typesetsh\HtmlToPdf\A_1B_Web();

$result = $service->render($html, \Typesetsh\UriResolver::all());

Last updated