PHP code example of setasign / setapdf-signer-addon-azure-keyvault
1. Go to this page and download the library: Download setasign/setapdf-signer-addon-azure-keyvault library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
setasign / setapdf-signer-addon-azure-keyvault example snippets
$loader = new \Example\Psr4AutoloaderClass;
$loader->register();
$loader->addNamespace('setasign\SetaPDF\Signer\Module\AzureKeyVault', 'path/to/src/');
use setasign\SetaPDF2\Core\Document;
use setasign\SetaPDF2\Core\Writer\FileWriter;
use setasign\SetaPDF2\Signer\Signer;
$httpClient = new GuzzleHttp\Client([
'http_errors' => false,
//'verify' => './cacert.pem'
]);
$azureModule = new setasign\SetaPDF\Signer\Module\AzureKeyVault\Module(
$vaultBaseUrl,
$certificateName,
$certificateVersion,
$httpClient,
new Http\Factory\Guzzle\RequestFactory(),
new Http\Factory\Guzzle\StreamFactory()
);
$token = $azureModule->createTokenBySharedSecret($tenantId, $appClientId, $appClientSecret);
$azureModule->setAccessToken($token['accessToken']);
// the file to sign
$fileToSign = __DIR__ . '/Laboratory-Report.pdf';
// create a writer instance
$writer = new FileWriter('signed.pdf');
// create the document instance
$document = Document::loadByFilename($fileToSign, $writer);
// create the signer instance
$signer = new Signer($document);
$azureModule->setSignatureAlgorithm($alg);
$signer->sign($azureModule);