Skip to content

Commit

Permalink
Merge pull request #7 from Setasign/support-appearances
Browse files Browse the repository at this point in the history
Support appearances
  • Loading branch information
JanSlabon authored Jun 28, 2022
2 parents 72b4590 + c47fae2 commit e1908eb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
49 changes: 49 additions & 0 deletions examples/appearance-demo.php
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);
10 changes: 9 additions & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public function setCertificate($certificate)
$this->padesModule->setCertificate($certificate);
}

/**
* @return \SetaPDF_Signer_X509_Certificate|string
*/
public function getCertificate()
{
return $this->padesModule->getCertificate();
}

/**
* @param string $signatureAlgorithm
*/
Expand Down Expand Up @@ -169,7 +177,7 @@ public function getCms()
public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath)
{
// ensure certificate
$certificate = $this->padesModule->getCertificate();
$certificate = $this->getCertificate();
if ($certificate === null) {
throw new \BadMethodCallException('Missing certificate!');
}
Expand Down

0 comments on commit e1908eb

Please sign in to comment.