PSPDFSigner


@interface PSPDFSigner
    : NSObject <PSPDFDocumentSignerDelegate, PSPDFDocumentSignerDataSource,
                PSPDFExternalSignature, NSCoding>

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, and VeriSign.PPKVS. Returns Adobe.PPKLite as default value, as it’s the only value supported for now.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull filter;

    Swift

    var filter: String { get }
  • The PDF SubFilter entry value. Typical values are adbe.x509.rsa_sha1, adbe.pkcs7.detached, and adbe.pkcs7.sha1. Returns adbe.pkcs7.detached as default value, as it’s the only value supported for now.

    Declaration

    Objective-C

    @property (readonly, nonatomic) NSString *_Nonnull subFilter;

    Swift

    var subFilter: String { get }
  • 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 (assign, readwrite, 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 (assign, readwrite, 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 to I agree with the terms of this contract.

    Declaration

    Objective-C

    @property (assign, readwrite, nonatomic, nullable) NSString *reason;

    Swift

    var reason: String? { get set }
  • The place where this signature was created. For example, ‘Vienna’.

    Declaration

    Objective-C

    @property (assign, readwrite, 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 custom delegate object that will perform the actual signing, you must set this property.

    Declaration

    Objective-C

    @property (assign, readwrite, 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 (readwrite, nonatomic)
        id<PSPDFDocumentSignerDataSource> _Nullable dataSource;

    Swift

    weak var dataSource: PSPDFDocumentSignerDataSource? { 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 (readwrite, nonatomic)
        id<PSPDFDocumentSignerDelegate> _Nullable delegate;

    Swift

    weak var delegate: PSPDFDocumentSignerDelegate? { get set }
  • Builds a document where element is prepared with a custom appearance and filled with contents of estimatedSize.

    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. If nil, 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 a PSPDFBlankSignatureContents to simply fill the signature contents with zeros.

    dataSink

    The destination data sink for the prepared document.

  • Embeds signature contents in a form signature element. It assumes that the document that contains element has been prepared for digital signatures by calling prepareFormElement: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.

  • 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: PSPDFSignatureHashAlgorithm) -> Data
  • Signs the passed form element element and writes the signed document to dataSink. 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: PSPDFSignatureFormElement, withCertificate certificate: PSPDFX509, writeTo dataSink: PSPDFDataSink, completionBlock: ((Bool, PSPDFDataSink?, 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.

  • Signs the passed form element element and writes the signed document to path. 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: PSPDFSignatureFormElement, withCertificate certificate: PSPDFX509, writeTo path: String, completionBlock: ((Bool, PSPDFDocument?, 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.

  • (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. sourceController should be of type UINavigationController.

    Declaration

    Objective-C

    - (void)requestSigningCertificate:(nonnull id)sourceController
                      completionBlock:
                          (nullable void (^)(PSPDFX509 *_Nullable,
                                             NSError *_Nullable))completionBlock;

    Swift

    func requestSigningCertificate(_ sourceController: Any, completionBlock: ((PSPDFX509?, Error?) -> Void)? = nil)