> For the complete documentation index, see [llms.txt](https://docs.typeset.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.typeset.sh/advanced-guides/signing-a-pdf.md).

# 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](/advanced-guides/save-handlers.md).

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

$signature = new \Typesetsh\HtmlToPdf\Signature($cert);
$signature->ContactInfo = 'contact@typeset.sh';
$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());
$result->toFile(__DIR__.'/hello.signed.pdf');
```
