typeset.sh
  • Getting started
    • Installation
    • Using typeset.sh
    • First template
    • CSS and paged media
      • Page counters
      • Page selectors
      • Page groups
      • Running elements
      • Bleed area
    • Convert from URL
    • Document Metadata
  • Advanced guides
    • QR codes
    • Save handlers
    • Error handling
    • Signing a PDF
    • PDF Standards
      • ZUGFeRD
      • PDF/A
      • PDF/UA
      • PDF/X-4
    • Color profiles
    • JavaScript
    • Common Object/Classes
      • createPdf function
      • HtmlToPdf
      • Result Object
    • Changelog
Powered by GitBook
On this page
  1. Advanced guides

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.

<?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');
PreviousError handlingNextPDF Standards

Last updated 2 years ago