use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use setasign\SetaPDF2\Core\Document as Document;
use setasign\SetaPDF2\Core\Writer\FileWriter as FileWriter;
use setasign\SetaPDF2\Signer\Signature\Module\Pades as Pades;
use setasign\SetaPDF2\Signer\Signer as Signer;
use setasign\SetaPDF\Signer\Module\GlobalSign\Dss;
// set up the client and identity
$options = [
'http_errors' => false,
'cert' => 'path/to/tls-cert.pem',
'ssl_key' => 'path/to/private/key.pem'
];
$apiKey = 'xxxxxxxxxxxxxxxx';
$apiSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$httpClient = new \GuzzleHttp\Client($options);
$client = new Dss\Client($httpClient, new RequestFactory(), new StreamFactory(), $apiKey, $apiSecret);
$identity = $client->getIdentity();
// now start the signature process
$writer = new FileWriter('signed.pdf');
$document = Document::loadByFilename('invoice.pdf', $writer);
$signer = new Signer($document);
$signer->setSignatureContentLength(15000);
$pades = new Pades();
$module = new Dss\SignatureModule($signer, $client, $identity, $pades);
$signer->sign($module);
use setasign\SetaPDF\Signer\Module\GlobalSign\Dss;
$tsmodule = new Dss\TimestampModule($client);