-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from Setasign/support-appearances
Support appearances
- Loading branch information
Showing
2 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
use Aws\Kms\KmsClient; | ||
use setasign\SetaPDF\Signer\Module\AwsKMS\Module; | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$fileToSign = __DIR__ . '/assets/Laboratory-Report.pdf'; | ||
$resultPath = 'signed.pdf'; | ||
|
||
$settings = require 'settings.php'; | ||
$region = $settings['region']; | ||
$version = $settings['version']; | ||
$keyId = $settings['keyId']; | ||
$cert = $settings['cert']; | ||
$signatureAlgorithm = $settings['algorithm']; | ||
|
||
$kmsClient = new KmsClient([ | ||
'region' => $region, | ||
'version' => $version, | ||
]); | ||
$awsKmsModule = new Module($keyId, $kmsClient); | ||
|
||
$awsKmsModule->setCertificate($cert); | ||
$awsKmsModule->setSignatureAlgorithm($signatureAlgorithm); | ||
|
||
// create a writer instance | ||
$writer = new SetaPDF_Core_Writer_File($resultPath); | ||
// create the document instance | ||
$document = SetaPDF_Core_Document::loadByFilename($fileToSign, $writer); | ||
|
||
// create the signer instance | ||
$signer = new SetaPDF_Signer($document); | ||
|
||
$field = $signer->addSignatureField( | ||
'Signature', | ||
1, | ||
SetaPDF_Signer_SignatureField::POSITION_RIGHT_TOP, | ||
['x' => -160, 'y' => -100], | ||
180, | ||
60 | ||
); | ||
|
||
$signer->setSignatureFieldName($field->getQualifiedName()); | ||
|
||
$appearance = new SetaPDF_Signer_Signature_Appearance_Dynamic($awsKmsModule); | ||
$signer->setAppearance($appearance); | ||
|
||
$signer->sign($awsKmsModule); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters