How do I get the Image of the Ink Signature from a PSPDFSignatureViewController?

Option 1

Subclass the PSPDFSignatureViewController and override its done: method, to access its drawView in order to create the ink signature.

Once you have the ink signature, you can use -[PSPDFAnnotation imageWithSize:withOptions:] to create a UIImage of the ink annotation, like so:

Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class CustomSignatureViewController: PSPDFSignatureViewController {
    override func done(_ sender: Any?) {
        super.done(sender)

        // The current document.
        let document = ...
        let pageInfo = document.pageInfoForPage(at:0)!;
		let pointSequences = self.drawView.pointSequences		
        let lines = PSPDFConvertViewLinesToPDFLines(pointSequences, pageInfo, CGRect(origin: .zero, size: pageInfo.size))
        let inkAnnotation = PSPDFInkAnnotation(lines: lines);
		
        // Create the `UIImage` from the ink annotation in your `PSPDFSignatureViewController`.
        let image = inkAnnotation.image(size: inkAnnotation.boundingBox.size, options: nil)
    }
}

Option 2

If for whatever reason, the PSPDFSignatureViewController is being presented in a context in which a PSPDFDocument is not available to get a reference PSPDFPageInfo object to perform the annotation calculations, you can call PSPDFDrawView.drawHierarchy(in:afterScreenUpdates:) within an image rendering context to get a direct image out of the PSPDFDrawView:

Copy
1
2
3
4
5
6
7
8
9
10
11
class CustomSignatureViewController: PSPDFSignatureViewController {
    override func done(_ sender: Any?) {
        super.done(sender)
        
        let rect = // ...
        let renderer = UIGraphicsImageRenderer(size: rect.size)
        let image = renderer.image { _ in
            self.drawView.drawHierarchy(in: rect, afterScreenUpdates: true)
        }
    }
}

For more details about accessing properties from a PSPDFSignatureViewController and its drawView, take a look at AccessInkSignatureBiometricDataExample.swift and PSCSignAllPagesExample.m from our PSPDFCatalog app.