dealfonso / sapp

Simple and Agnostic PDF Document Parser in PHP - sign PDF docs using PHP
GNU Lesser General Public License v3.0
110 stars 29 forks source link

Add signature options feature #66

Closed aphoe closed 3 months ago

aphoe commented 3 months ago

Developers can now add signature options (e.g., Name, Reason, Location, and ContactInfo) to a document's digital signature.

How it works

// Create an array with the fields
$options = [
  'Name' => '*** Name of signer***',
  'Reason' => '*** Reason for signing ***',
  'Location' => '*** Geographical location where it was signed ***',
  'ContactInfo' => '*** contact information associated with the signer ***',
];

$certificate = [
  'cert' => $certificate,
  'pkey' => $private_key,
];

$content = file_get_contents('path/to/file.pdf');
$obj = PDFDoc::from_string($content);

$obj->set_signature_certificate($certificate);
$obj->set_signature_options($options); // Use this method to set the options

$signed = $obj->to_pdf_file_s();

file_put_contents('path/to/save/signed/file.pdf', $signed);