setasign\SetaPDF2\Signer

Signer The main class of the SetaPDF-Signer Component

File: /SetaPDF v2/Signer/Signer.php
Old class name (alias): \SetaPDF_Signer

Class hierarchy

Summary

Constants

CERTIFICATION_LEVEL_FORM_FILLING

Certification level constant

CERTIFICATION_LEVEL_FORM_FILLING_AND_ANNOTATIONS

Certification level constant

CERTIFICATION_LEVEL_NONE

public const int Signer::CERTIFICATION_LEVEL_NONE = 0

Certification level constant

CERTIFICATION_LEVEL_NO_CHANGES_ALLOWED

Certification level constant

PROP_CONTACT_INFO

public const string Signer::PROP_CONTACT_INFO = 'ContactInfo'

Property constant

PROP_LOCATION

public const string Signer::PROP_LOCATION = 'Location'

Property constant

PROP_NAME

public const string Signer::PROP_NAME = 'Name'

Property constant

PROP_REASON

public const string Signer::PROP_REASON = 'Reason'

Property constant

PROP_TIME_OF_SIGNING

public const string Signer::PROP_TIME_OF_SIGNING = 'M'

Property constant

VERSION

public const string Signer::VERSION = '2.48.0.2155'

Version


Properties

$_allowSignatureContentLengthChange

Defines if the signatureContentLength property can be changed automatically, if a signature value doesn't fit into the reserved space.

$_appearance

An appearance instance

$_byteRange

The byte range value

$_certificationLevel

protected int Signer::$_certificationLevel = 0

The certification level

$_document

Document which shall be signed

$_fieldName

protected string Signer::$_fieldName = 'Signature'

The signature field name

$_offsetEndPlaceholder

protected string Signer::$_offsetEndPlaceholder = '(<---OFFSET--->)'

A placeholder for the second length value in the ByteRange array

$_placeHolderByteOffset

The byte offset position of the place holder/reserved space

$_secHandlerCallback

protected ?callback Signer::$_secHandlerCallback

The callback for authenticating at the security handler of the document

$_signatureContentLength

protected int Signer::$_signatureContentLength = 15000

The byte length of the reserved space for the signature content

$_signatureProperties

protected array Signer::$_signatureProperties = array(...)

The signature properties

$_tempDocument

A temporary instance of the signed document

$_tempWriter

The temporary writer instance

$_timestampModule

A timestamp module interface


Static Methods

getCertificationLevelByDocument()

Check a PDF document for a certification signature and its level

Parameters
$document : \setasign\SetaPDF2\Core\Document
 
Return Values

The certification level or null if the document has no certification signature.

Exceptions

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

getSignatureFieldNames()

sanitizeSaveMethod()

public static Signer::sanitizeSaveMethod (
int $document,
$saveMethod
): int

Sanitize the $saveMethod parameter for the intermediate save() call

This method checks if the $saveMethod parameter can be kept or if it has to be changed to Document::SAVE_METHOD_UPDATE.

It has to be changed to "update" as soon as an existing signature exists or the document includes usage rights.

Parameters
$document : int
 
$saveMethod
 
Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception


Methods

__construct()

public Signer::__construct (
\setasign\SetaPDF2\Core\Document $document,
?callback $secHandlerCallback = null
)

The constructor.

If the passed document is protected by a security handler it is possible to pass a callback as second parameter that will be called if an authentication is needed.

Parameters
$document : \setasign\SetaPDF2\Core\Document

The document instance

$secHandlerCallback : ?callback

A callback which should auth on a security handler (if needed). The callback will be called with two parameters: The first parameter will be the security handler and the second parameter is the current document instance. It should return true or false whether the authentication was successful or not.

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

_addDocMp()

Adds the document modification detection and prevention data.

Parameters
$dictionary : \setasign\SetaPDF2\Core\Type\PdfDictionary
 

_callSecHandlerCallback()

Calls a defined callback that should authenticate on the documents security handler.

Parameters
$document : \setasign\SetaPDF2\Core\Document

The document instance

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

_checkCertificationLevel()

protected Signer::_checkCertificationLevel (
void
): void

Verifies if the defined certification level can be applied.

Certification signatures can only be applied if the document has no other existing signature.

Exceptions

Throws Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

_createSignatureDictionary()

Creates the signature dictionary.

Parameters
$field : SignatureField

The signature field

$module : ?Signature\Module\DictionaryInterface
 
Exceptions

Throws \Exception

_createTimestampSignatureDictionary()

Creates the signature dictionary.

Parameters
$field : SignatureField

The signature field

$module : ?Signature\Module\DictionaryInterface
 

_ensureSignatureField()

protected Signer::_ensureSignatureField (
\setasign\SetaPDF2\Core\Document $document,
bool $returnFieldInstance = false
): ?SignatureField

Ensures a valid signature field instance.

Parameters
$document : \setasign\SetaPDF2\Core\Document

The document instance

$returnFieldInstance : bool

If true the field instance will be returned, otherwise null will be returned.

Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws Exception

_updateAcroForm()

Updates the AcroForm dictionary.

Parameters
$document : \setasign\SetaPDF2\Core\Document

The document instance

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

addSignatureField()

public Signer::addSignatureField (
string $fieldName = SignatureField::DEFAULT_FIELD_NAME,
int $pageNumber = 1,
int|string $xOrPosition = 0,
int|array $yOrTranslate = 0,
int $width = 0,
int $height = 0
): SignatureField

Proxy method for SignatureField::add().

Parameters
$fieldName : string

The field name in UTF-8 encoding

$pageNumber : int

The page number on which the signature field shall appear.

$xOrPosition : int|string

Integer with the x-position or SignatureField::POSITION_XXX

$yOrTranslate : int|array

Integer with the y-position (if $xOrPosition is an integer) or an array with the keys 'x' and 'y'

$width : int

Width of the signature field

$height : int

Height of the signature field

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\Core\Exception

See

addTimeStamp()

public Signer::addTimeStamp (
string $signature,
TmpDocument $tmpDocument
): string

Forwards the signature to a timestamp module and merges the result into the signature container.

Parameters
$signature : string
 
$tmpDocument : TmpDocument
 
Exceptions

Throws Asn1\Exception

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws Exception

cleanUp()

public Signer::cleanUp (
void
): void

Release memory and cycled references.

createSignature()

public Signer::createSignature (): string

Creates a signature based on a temporary document instance and a signature module.

Parameters
$tmpDocument : TmpDocument
 
$module : Signature\Module\ModuleInterface
 
Exceptions

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws Exception

See

createTimestampSignature()

public Signer::createTimestampSignature (
TmpDocument $tmpDocument
): string

Creates a timestamp signature based on a temporary document instance.

The timestamp module has to be added to the signer instance through the setTimestampModule() method.

Parameters
$tmpDocument : TmpDocument
 
Exceptions

Throws Exception\ContentLength

Throws Exception

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

See

getAllowSignatureContentLengthChange()

Get the flag specifying whether the signature content length (reserved space) could be changed automatically ot not.

getAppearance()

Get the current appearance module.

getContactInfo()

public Signer::getContactInfo (
void
): bool|string

Get the information provided by the signer to enable a recipient to contact the signer to verify the signature.

Return Values

If no contact info exist FALSE will be returned. Otherwise, the value will be returned.

See

getLocation()

public Signer::getLocation (
void
): bool|string

Get the CPU host name or physical location of the signing.

Return Values

If no location exist FALSE will be returned. Otherwise the value will be returned.

See

getName()

public Signer::getName (
void
): bool|string

Get the name of the person or authority signing the document.

Return Values

If no name exist FALSE will be returned. Otherwise the value will be returned.

See

getReason()

public Signer::getReason (
void
): bool|string

Get the reason for the signing.

Return Values

If no name exist FALSE will be returned. Otherwise the value will be returned.

See

getSignatureContentLength()

public Signer::getSignatureContentLength (
void
): int

Get the signature content length that will be used to reserve space for the final signature.

getSignatureField()

public Signer::getSignatureField (
string $fieldName = SignatureField::DEFAULT_FIELD_NAME,
bool $create = true
): bool|SignatureField

Proxy method to SignatureField::get().

Parameters
$fieldName : string

The field name in UTF-8 encoding

$create : bool

Automatically creates a hidden field if none was found by the specified name

Exceptions

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws Exception

Throws \setasign\SetaPDF2\Core\Exception

See

getSignatureProperty()

public Signer::getSignatureProperty (
string $name
): bool|string

Get a signature property.

Parameters
$name : string

See and use Signer::PROP_* constants for valid names

Return Values

If the name is not valid FALSE will be returned. Otherwise the value will be returned.

getTimeOfSigning()

getTimestampModule()

Get the current timestamp module.

preTimestamp()

Prepares a temporary document instance to be used further in an asynchronous timestamp workflow.

Parameters
$writer : \setasign\SetaPDF2\Core\Writer\FileInterface
 
$module : ?Signature\Module\DictionaryInterface
 
$saveMethod : int

The $method parameter passed to sanitizeSaveMethod() and finally

  •                      passed to the main <a href="/api-reference/setapdf/c/setasign.SetaPDF2.Core.Document#method_save">\setasign\SetaPDF2\Core\Document::save()</a> call of the
    
  •                      document instance.
    
Exceptions

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotDefinedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Exception

Throws Exception

See

saveSignature()

public Signer::saveSignature (
TmpDocument $tmpDocument,
string $signature
): void

Add a signature result to the temporary document instance and saves it to the main documents writer instance.

Parameters
$tmpDocument : TmpDocument
 
$signature : string

The PKCS7 byte string to be added to the temporary document.

Exceptions

Throws Exception\ContentLength

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws Exception

setAllowSignatureContentLengthChange()

public Signer::setAllowSignatureContentLengthChange (
bool $allowSignatureContentLengthChange
): void

Set a flag specifying whether the signature content length (reserved space) could be changed automatically or not.

If this value is set to true and the resulting signature is bigger than the reserved space (defined by Signer::setSignatureContentLength() the signature content length will be increased and the signature process will restart.

Parameters
$allowSignatureContentLengthChange : bool

The flag status

setAppearance()

public Signer::setAppearance (): void

Set an appearance instance.

Parameters
$appearance : ?Signature\Appearance\AbstractAppearance

The appearance instance

setCertificationLevel()

public Signer::setCertificationLevel (
int $certificationLevel
): void

Set the certification level.

Parameters
$certificationLevel : int

Possible values are defined in the Signer::CERTIFICATION_LEVEL_XXX constants.

See

setContactInfo()

public Signer::setContactInfo (
string $contactInfo
): void

Set the information provided by the signer to enable a recipient to contact the signer to verify the signature.

Parameters
$contactInfo : string

The contact info in UTF-8 encoding

See

setLocation()

public Signer::setLocation (
string $location
): void

Set the host name or physical location of the signing.

Parameters
$location : string

The physical location or host name in UTF-8 encoding

See

setName()

public Signer::setName (
string $name
): void

Set the name of the person or authority signing the document.

Parameters
$name : string

The value in UTF-8 encoding

See

setReason()

public Signer::setReason (
string $reason
): void

Set the reason for the signing.

Parameters
$reason : string

The reason for the signing in UTF-8 encoding

See

setSignatureContentLength()

public Signer::setSignatureContentLength (
int $length
): void

Set the signature content length that will be used to reserve space for the final signature.

Parameters
$length : int

The length of the signature content.

setSignatureFieldName()

public Signer::setSignatureFieldName (
string $fieldName
): void

Set the signature field name.

This can be the name of an existing signature field or an individual name which will be used to create a hidden field automatically.

Parameters
$fieldName : string

The field name in UTF-8 encoding

setSignatureProperty()

public Signer::setSignatureProperty (
string $name,
string $value
): void

Set a signature property.

Parameters
$name : string

See and use Signer::PROP_* constants for valid names

$value : string

The value in UTF-8 encoding

Exceptions

Throws \InvalidArgumentException if the name is not valid

setTimeOfSigning()

Set the time of signing.

Parameters
$timeOfSigning : string|\DateTime|\setasign\SetaPDF2\Core\DataStructure\Date

The time of signing in UTF-8 encoding

See

setTimestampModule()

Set a timestamp module.

Parameters
$module : ?Timestamp\Module\ModuleInterface

The timestamp module instance

sign()

Digital signs the initial document.

The \setasign\SetaPDF2\Core\Document instance will be temporary saved and finished. It is not possible to work on it further. The final PDF will be passed to the previously attached writer instance, so that the final signed document will be written to the correct writer.

Parameters
$module : Signature\Module\ModuleInterface

The module instance

$saveMethod : int

The $method parameter passed to sanitizeSaveMethod() and finally passed to the main \setasign\SetaPDF2\Core\Document::save() call of the document instance.

Exceptions

Throws Exception\ContentLength

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotDefinedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Exception

Throws Exception

timestamp()

Adds a document level timestamp.

The \setasign\SetaPDF2\Core\Document instance will be temporary saved and finished. It is not possible to work on it further. The final PDF will be passed to the previously attached writer instance, so that the final signed document will be written to the correct writer.

Parameters
$saveMethod : int

The $method parameter passed to sanitizeSaveMethod() and finally passed to the main \setasign\SetaPDF2\Core\Document::save() call of the document instance.

Return Values

The timestamp token/signature

Exceptions

Throws Exception\ContentLength

Throws \setasign\SetaPDF2\Core\Exception

Throws \setasign\SetaPDF2\Core\Type\IndirectReference\Exception

Throws \setasign\SetaPDF2\NotImplementedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotDefinedException

Throws \setasign\SetaPDF2\Core\Document\ObjectNotFoundException

Throws \setasign\SetaPDF2\Core\Parser\Exception

Throws \setasign\SetaPDF2\Core\Reader\Exception

Throws \setasign\SetaPDF2\Core\SecHandler\Exception

Throws \setasign\SetaPDF2\Core\Type\Exception

Throws \setasign\SetaPDF2\Exception

Throws Exception