|
| 1 | +<?php |
| 2 | + |
| 3 | +use Aws\Kms\KmsClient; |
| 4 | +use setasign\SetaPDF\Signer\Module\AwsKMS\Module; |
| 5 | + |
| 6 | +require_once __DIR__ . '/../vendor/autoload.php'; |
| 7 | + |
| 8 | +$fileToSign = __DIR__ . '/assets/Laboratory-Report.pdf'; |
| 9 | +$resultPath = 'signed.pdf'; |
| 10 | + |
| 11 | +$settings = require 'settings.php'; |
| 12 | +$region = $settings['region']; |
| 13 | +$version = $settings['version']; |
| 14 | +$keyId = $settings['keyId']; |
| 15 | +$cert = $settings['cert']; |
| 16 | +$signatureAlgorithm = $settings['algorithm']; |
| 17 | + |
| 18 | +$kmsClient = new KmsClient([ |
| 19 | + 'region' => $region, |
| 20 | + 'version' => $version, |
| 21 | +]); |
| 22 | +$awsKmsModule = new Module($keyId, $kmsClient); |
| 23 | + |
| 24 | +$awsKmsModule->setCertificate($cert); |
| 25 | +$awsKmsModule->setSignatureAlgorithm($signatureAlgorithm); |
| 26 | + |
| 27 | +// create a writer instance |
| 28 | +$writer = new SetaPDF_Core_Writer_File($resultPath); |
| 29 | +// create the document instance |
| 30 | +$document = SetaPDF_Core_Document::loadByFilename($fileToSign, $writer); |
| 31 | + |
| 32 | +// create the signer instance |
| 33 | +$signer = new SetaPDF_Signer($document); |
| 34 | + |
| 35 | +$field = $signer->addSignatureField( |
| 36 | + 'Signature', |
| 37 | + 1, |
| 38 | + SetaPDF_Signer_SignatureField::POSITION_RIGHT_TOP, |
| 39 | + ['x' => -160, 'y' => -100], |
| 40 | + 180, |
| 41 | + 60 |
| 42 | +); |
| 43 | + |
| 44 | +$signer->setSignatureFieldName($field->getQualifiedName()); |
| 45 | + |
| 46 | +$appearance = new SetaPDF_Signer_Signature_Appearance_Dynamic($awsKmsModule); |
| 47 | +$signer->setAppearance($appearance); |
| 48 | + |
| 49 | +$signer->sign($awsKmsModule); |
0 commit comments