PSPDFSigner
Objective-C
@interface PSPDFSigner
: NSObject <PSPDFDocumentSignerDelegate, PSPDFDocumentSignerDataSource,
PSPDFExternalSignature, NSSecureCoding>
Swift
class PDFSigner : NSObject, PDFDocumentSignerDelegate, PDFDocumentSignerDataSource, ExternalSignature, NSSecureCoding
PSPDFSigner
is an abstract signer class. Override methods in subclasses as necessary.
-
The PDF filter name to use for this signer. Typical values are
Adobe.PPKLite
,Entrust.PPKEF
,CICI.SignIt
, andVeriSign.PPKVS
. ReturnsAdobe.PPKLite
as default value, as it’s the only value supported for now.Declaration
Objective-C
@property (nonatomic, readonly) NSString *_Nonnull filter;
Swift
var filter: String { get }
-
Deprecated
Deprecated in PSPDFKit 5.1 for macOS. Use
signatureType
instead.The PDF SubFilter entry value. Tied to
signatureType
. Typical values areETSI.CAdES.detached
,adbe.pkcs7.detached
, andadbe.pkcs7.sha1
.Set
signatureType
to modify the subFilter.Declaration
Objective-C
@property (nonatomic, readonly) PSPDF_DEPRECATED(10.1, 5.1, "Use `signatureType` instead.") NSString *subFilter;
Swift
var subFilter: String { get }
-
The PDF Digital Signature type. This translated directly to signature “SubFilter” type in the PDF . Returns
PSPDFSignatureTypeCMS
by default, as it’s the only value fully supported for now. Other values arePSPDFSignatureTypeSHA1
(deprecated), andPSPDFSignatureTypePades
for advanced digital signatures which are only partially supported.Declaration
Objective-C
@property (nonatomic) PSPDFSignatureType signatureType;
Swift
var signatureType: PDFSignatureType { get set }
-
The name that will be displayed in the signature UI to identify this signer.
Note
This is not the signer’s name that will appear in the signature itself. The signer’s name always comes from the certificate that was used to sign the document.Declaration
Objective-C
@property (nonatomic, nullable) NSString *displayName;
Swift
var displayName: String? { get set }
-
The person or entity who signed the document. Important: For security reasons, if the API requires you to pass a certificate for signing, the CN of the certificate will be used and this field will be ignored.
Declaration
Objective-C
@property (nonatomic, nullable) NSString *signersName;
Swift
var signersName: String? { get set }
-
The reason that will be embedded in every digital signature created by this instance of
PSPDFSigner
. For example, if you are signing a PDF contract you can set this property toI agree with the terms of this contract
.Declaration
Objective-C
@property (nonatomic, nullable) NSString *reason;
Swift
var reason: String? { get set }
-
The place where this signature was created. For example, ‘Vienna’.
Declaration
Objective-C
@property (nonatomic, nullable) NSString *location;
Swift
var location: String? { get set }
-
Private key from the certificate used to produce the signature by encrypting the message digest from the PDF file. (see details https://pspdfkit.com/guides/ios/current/features/digital-signatures/).
Note
If you don’t set a customdelegate
object that will perform the actual signing, you must set this property.Declaration
Objective-C
@property (nonatomic, nullable) PSPDFPrivateKey *privateKey;
Swift
var privateKey: PSPDFPrivateKey? { get set }
-
The data source responsible for providing information about the digital signature, like the algorithms that will be used to hash and encrypt, whether biometric properties should also be embedded or not, or the visual appearance that the signature form element will have once the document is saved.
Declaration
Objective-C
@property (nonatomic, weak) id<PSPDFDocumentSignerDataSource> _Nullable dataSource;
Swift
weak var dataSource: PDFDocumentSignerDataSource? { get set }
-
The delegate that will be called when the actual signing process is taking place. It gives the opportunity to customize the signature process in an asynchronous way. If this delegate is not set, a default digital signature will be created by using the
privateKey
property of the receiver.Declaration
Objective-C
@property (nonatomic, weak) id<PSPDFDocumentSignerDelegate> _Nullable delegate;
Swift
weak var delegate: PDFDocumentSignerDelegate? { get set }
-
Builds a document where
element
is prepared with a custom appearance and filled withcontents
ofestimatedSize
.Declaration
Objective-C
- (void)prepareFormElement:(nonnull PSPDFSignatureFormElement *)element toBeSignedWithAppearance: (nonnull PSPDFSignatureAppearance *)signatureAppearance contents:(nonnull id<PSPDFSignatureContents>)contents writingToDataSink:(nonnull id<PSPDFDataSink>)dataSink completion: (nonnull PSPDFSignatureCreationBlock)completionBlock;
Parameters
element
The signature form element to sign.
signatureAppearance
The
PSPDFSignatureAppearance
instance that customizes how the signature will appear in the signed document. Ifnil
, the default signature appearance will be used.contents
An implementation of the
PSPDFSignatureContents
protocol that will be used to fill the digital signature contents. Typically, you will want to pass an instance of aPSPDFBlankSignatureContents
to simply fill the signature contents with zeros.dataSink
The destination data sink for the prepared document. - see:
PSPDFDataSink
.completionBlock
A closure called after preparation succeeds or fails.
-
Embeds signature contents in a form signature
element
. It assumes that the document that containselement
has been prepared for digital signatures by callingprepareFormElement:toBeSignedWithAppearance:contents:writingToDataSink:completion:
before.Declaration
Objective-C
- (void)embedSignatureInFormElement:(nonnull PSPDFSignatureFormElement *)element withContents:(nonnull id<PSPDFSignatureContents>)contents writingToDataSink:(nonnull id<PSPDFDataSink>)dataSink completion:(nonnull PSPDFSignatureCreationBlock) completionBlock;
Parameters
element
The signature form element to sign.
contents
An implementation of the
PSPDFSignatureContents
protocol that will be used to fill the digital signature contents.dataSink
The destination data sink for the prepared document. - see:
PSPDFDataSink
.completionBlock
A closure called after embedding succeeds or fails.
-
This method signs a piece of data using a private key and uses
hashAlgorithm
for the signature padding.Declaration
Objective-C
- (nonnull NSData *)signData:(nonnull NSData *)data privateKey:(nonnull PSPDFPrivateKey *)privateKey hashAlgorithm:(PSPDFSignatureHashAlgorithm)hashAlgorithm;
Swift
func sign(_ data: Data, privateKey: PSPDFPrivateKey, hashAlgorithm: PDFSignatureHashAlgorithm) -> Data
-
Signs the passed form element
element
and writes the signed document todataSink
. The completion block will signal if the result was successful, return the signed document, if it was signed correctly, and the signing error, if there’s any.Declaration
Objective-C
- (void)signFormElement:(nonnull PSPDFSignatureFormElement *)element withCertificate:(nonnull PSPDFX509 *)certificate writeToDataSink:(nonnull id<PSPDFDataSink>)dataSink completionBlock:(nullable void (^)(BOOL, id<PSPDFDataSink> _Nullable, NSError *_Nullable))completionBlock;
Swift
func sign(_ element: SignatureFormElement, withCertificate certificate: X509, writeTo dataSink: DataSink, completionBlock: ((Bool, DataSink?, Error?) -> Void)? = nil)
Parameters
element
The signature form element to sign.
certificate
The X509 certificate that will be used to create the digital signature.
dataSink
The destination data sink for the signed document. - see:
PSPDFDataSink
.completionBlock
A closure called after signing succeeds or fails.
-
Signs the passed form element
element
and writes the signed document topath
. The completion block will signal if the result was successful, return the signed document, if it was signed correctly, and the signing error, if there’s any.Declaration
Objective-C
- (void)signFormElement:(nonnull PSPDFSignatureFormElement *)element withCertificate:(nonnull PSPDFX509 *)certificate writeTo:(nonnull NSString *)path completionBlock:(nullable void (^)(BOOL, PSPDFDocument *_Nullable, NSError *_Nullable))completionBlock;
Swift
func sign(_ element: SignatureFormElement, withCertificate certificate: X509, writeTo path: String, completionBlock: ((Bool, Document?, Error?) -> Void)? = nil)
Parameters
element
The signature form element to sign.
certificate
The X509 certificate that will be used to create the digital signature.
path
The destination path for the signed document.
completionBlock
A closure called after signing succeeds or fails.
-
Unavailable
Not available in PSPDFKit for macOS
(Override) This method requests the signing certificate on demand. If the certificate is for instance password protected or must be fetched over the network, you can push a custom
UIViewController
on the passed navigation controller to display a custom UI while unlocking/fetching the certificate. If you are done, call the done handler with the fetched certificate and/or and error value. Subclasses ofPSPDFSigner
must override this method. Overrides must not call super.Declaration
Parameters
sourceController
A
UINavigationController
on which to push the UI for unlocking/fetching the certificate.completionBlock
A closure to be called after the certificate has been fetched or the request failed.